From 051f6c12e7d003b30b2972d30bdcc4f8464ef11b Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 1 Sep 2025 11:58:27 -0700 Subject: [PATCH 1/3] Add error logging for unexpected Redis disconnections --- src/repositories/BaseRedisRepository.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/repositories/BaseRedisRepository.ts b/src/repositories/BaseRedisRepository.ts index e66acc1..4b39bfd 100644 --- a/src/repositories/BaseRedisRepository.ts +++ b/src/repositories/BaseRedisRepository.ts @@ -13,6 +13,9 @@ export abstract class BaseRedisRepository { }), ) { this.redisClient = redisClient; + this.redisClient.on('error', (err) => { + console.error(err.stack); + }); } get isReady() { From 72b77c3b60b92af5ed062464ee32384d66707bc0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 1 Sep 2025 12:06:23 -0700 Subject: [PATCH 2/3] Add a reconnection interval constant --- src/environment.ts | 1 + src/repositories/BaseRedisRepository.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) 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 4b39bfd..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,7 +10,8 @@ export abstract class BaseRedisRepository { socket: { tls: process.env.NODE_ENV === 'production', rejectUnauthorized: false, - } + reconnectStrategy: REDIS_RECONNECT_INTERVAL, + }, }), ) { this.redisClient = redisClient; From f49113e67b1a3c336d50fdd52c57e983e9aa6dd0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 1 Sep 2025 12:14:47 -0700 Subject: [PATCH 3/3] Document the REDIS_URL environment variable --- .env.example | 3 +++ 1 file changed, 3 insertions(+) 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=