1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 16:30:58 -05:00

Replace janky reconnect method with a reliable one from the package.

This commit is contained in:
AnxietyisReal 2024-01-06 18:03:26 +11:00
parent d434507b9b
commit 543a84a433

View File

@ -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<any> {
let cachedResult:any;