Create a Redis Client in Node.js

For Salesforce Functions written in Node.js, use the node-redis (redis) package to access your Redis datastore. Access the REDIS_URL environment variable with process.env to create a Redis client instance.

1async function redisConnect() {
2  const REDIS_URL = process.env.REDIS_URL;
3  if (!REDIS_URL) {
4    throw new Error("REDIS_URL is not set");
5  }
6  // Connect to Redis
7  const redisClient = createClient({
8    url: REDIS_URL,
9    socket: {
10      tls: true,
11      rejectUnauthorized: false,
12    },
13  });
14
15  await redisClient.connect();
16  return redisClient;
17}

Product Retirement Announcement

Salesforce Functions is no longer available for purchase or renewal. To preserve the capabilities that Salesforce Functions provided to your org, deploy an alternative solution before your existing order term ends. See Salesforce Functions Retirement for more information on migrating your functions. Contact your Salesforce Account Executive for more information on Heroku.