mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
✨ feat: Add Redis Ping Interval Configuration (#8648)
Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
deb928bf80
commit
b050a0bf1e
4 changed files with 38 additions and 8 deletions
25
api/cache/redisClients.js
vendored
25
api/cache/redisClients.js
vendored
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue