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.
async function redisConnect() {
const REDIS_URL = process.env.REDIS_URL;
if (!REDIS_URL) {
throw new Error("REDIS_URL is not set");
}
// Connect to Redis
const redisClient = createClient({
url: REDIS_URL,
socket: {
tls: true,
rejectUnauthorized: false,
},
});
await redisClient.connect();
return redisClient;
}