From c69824e7b678f88f6dc7d1db6d5e9f2c83d39ac4 Mon Sep 17 00:00:00 2001 From: wajeht <58354193+wajeht@users.noreply.github.com> Date: Sat, 17 Sep 2022 12:03:14 -0400 Subject: [PATCH] fix: attempt to fix redis connection error --- src/utils/redis.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/utils/redis.js b/src/utils/redis.js index 8ae7a375..c86a36b3 100644 --- a/src/utils/redis.js +++ b/src/utils/redis.js @@ -3,21 +3,34 @@ import Redis from 'ioredis'; import logger from './logger.js'; import Chad from './chad.js'; -const client = new Redis({ - port: REDIS.port, // Redis port - host: REDIS.host, // Redis host - username: REDIS.username, // needs Redis >= 6 +const redisConfig = { + port: REDIS.port, + host: REDIS.host, + username: REDIS.username, password: REDIS.password, - db: REDIS.db, // Defaults to 0 -}); + db: REDIS.db, + autoResubscribe: false, + lazyConnect: true, + maxRetriesPerRequest: 0, +}; -client.on('error', (error) => { +let client; + +try { + client = new Redis(redisConfig); + logger.info(`Redis client started`); +} catch (e) { logger.error(e); Chad.flex(e.message, e.stack); -}); +} -client.on('connect', (error) => { - logger.info(`Redis client started`); -}); +// client.on('error', (error) => { +// logger.error(e); +// Chad.flex(e.message, e.stack); +// }); + +// client.on('connect', (error) => { +// logger.info(`Redis client started`); +// }); export default client;