diff --git a/.env.example b/.env.example index 1ce47a7..b111bba 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,6 @@ RATE_LIMITS_DISABLED= RATE_LIMIT_WINDOW_MS= RATE_LIMIT_DELAY_AFTER_REQUESTS= RATE_LIMIT_DELAY_MULTIPLIER_MS= + +# Redis connection +REDIS_URL= diff --git a/src/environment.ts b/src/environment.ts index bc193ff..b47673a 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -21,3 +21,4 @@ export const RATE_LIMIT_DELAY_MULTIPLIER_MS = process.env.RATE_LIMIT_DELAY_MULTI ? parseInt(process.env.RATE_LIMIT_DELAY_MULTIPLIER_MS) : 1000; +export const REDIS_RECONNECT_INTERVAL = 30000; diff --git a/src/repositories/BaseRedisRepository.ts b/src/repositories/BaseRedisRepository.ts index e66acc1..c5c8b73 100644 --- a/src/repositories/BaseRedisRepository.ts +++ b/src/repositories/BaseRedisRepository.ts @@ -1,4 +1,5 @@ import { createClient } from 'redis'; +import { REDIS_RECONNECT_INTERVAL } from "../environment"; export abstract class BaseRedisRepository { protected redisClient; @@ -9,10 +10,14 @@ export abstract class BaseRedisRepository { socket: { tls: process.env.NODE_ENV === 'production', rejectUnauthorized: false, - } + reconnectStrategy: REDIS_RECONNECT_INTERVAL, + }, }), ) { this.redisClient = redisClient; + this.redisClient.on('error', (err) => { + console.error(err.stack); + }); } get isReady() {