From 70acd9b7bf99d7f052c60a2737aed1b46045d56b Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Sat, 6 Jan 2024 18:03:26 +1100 Subject: [PATCH] Replace janky reconnect method with a reliable one from the package. --- src/components/CacheServer.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/components/CacheServer.ts b/src/components/CacheServer.ts index 93b10d5..44cfe94 100644 --- a/src/components/CacheServer.ts +++ b/src/components/CacheServer.ts @@ -6,7 +6,7 @@ const RedisClient = createClient({ url: (await TSClient()).redis_uri, database: 0, name: 'Daggerbot', - socket: { keepAlive: 15000, timeout: 30000 } + socket: { keepAlive: 15000, timeout: 30000, reconnectStrategy(retries:number = 5) {return Math.min(retries * 76, 1000)} } }); export default class CacheServer { @@ -14,16 +14,7 @@ export default class CacheServer { protected static eventManager() { RedisClient .on('connect', ()=>Logger.console('log', this.prefix, 'Connection to Redis has been established')) - .on('error', (err:ErrorReply)=>{ - Logger.console('error', this.prefix, `Encountered an error in Redis: ${err.message}`) - setTimeout(async()=>{ - if (!RedisClient.isReady) { - Logger.console('log', this.prefix, 'Client is zombified, starting a fresh connection...'); - RedisClient.quit(); - await RedisClient.connect(); - } - }, 1500) - }) + .on('error', (err:ErrorReply)=>Logger.console('error', this.prefix, `Encountered an error in Redis: ${err.message}`)) } public static async get(key:any, jsonMode:boolean):Promise { let cachedResult:any;