feat: Add Redis Ping Interval Configuration (#8648)

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Theo N. Truong 2025-07-25 09:00:02 -06:00 committed by GitHub
parent deb928bf80
commit b050a0bf1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 8 deletions

View file

@ -25,10 +25,13 @@ if (cacheConfig.USE_REDIS) {
? new IoRedis(cacheConfig.REDIS_URI, redisOptions)
: new IoRedis.Cluster(cacheConfig.REDIS_URI, { redisOptions });
// Pinging the Redis server every 5 minutes to keep the connection alive
const pingInterval = setInterval(() => ioredisClient.ping(), 5 * 60 * 1000);
ioredisClient.on('close', () => clearInterval(pingInterval));
ioredisClient.on('end', () => clearInterval(pingInterval));
// Pinging the Redis server to keep the connection alive (if enabled)
let pingInterval = null;
if (cacheConfig.REDIS_PING_INTERVAL > 0) {
pingInterval = setInterval(() => ioredisClient.ping(), cacheConfig.REDIS_PING_INTERVAL * 1000);
ioredisClient.on('close', () => clearInterval(pingInterval));
ioredisClient.on('end', () => clearInterval(pingInterval));
}
}
/** @type {import('@keyv/redis').RedisClient | import('@keyv/redis').RedisCluster | null} */
@ -48,10 +51,16 @@ if (cacheConfig.USE_REDIS) {
keyvRedisClient.setMaxListeners(cacheConfig.REDIS_MAX_LISTENERS);
// Pinging the Redis server every 5 minutes to keep the connection alive
const keyvPingInterval = setInterval(() => keyvRedisClient.ping(), 5 * 60 * 1000);
keyvRedisClient.on('disconnect', () => clearInterval(keyvPingInterval));
keyvRedisClient.on('end', () => clearInterval(keyvPingInterval));
// Pinging the Redis server to keep the connection alive (if enabled)
let pingInterval = null;
if (cacheConfig.REDIS_PING_INTERVAL > 0) {
pingInterval = setInterval(
() => keyvRedisClient.ping(),
cacheConfig.REDIS_PING_INTERVAL * 1000,
);
keyvRedisClient.on('disconnect', () => clearInterval(pingInterval));
keyvRedisClient.on('end', () => clearInterval(pingInterval));
}
}
module.exports = { ioredisClient, keyvRedisClient, GLOBAL_PREFIX_SEPARATOR };