Redis on Heroku – max number of clients reached

Viewed 200

I want to connect to Redis on Heroku yet I'm getting an error max number of clients reached. My Redis initialization is pretty simple:

const redis = require('redis');

// Client
const client = redis.createClient({ url: process.env.REDIS_URL });

// Listeners
client.on('error', (err) => console.log('Redis Client Error', err));
client.on('connect', () => console.log('Redis Client Connected'));

// Connection
client.connect();

I'm wondering if I'm doing it correctly though, as I'm creating this connection for every work (process.env.WEB_CONCURRENCY) and then probably having it on every running dyno.

What can be done to avoid this issue?

0 Answers
Related