Stop spamming redis if it slows down

This commit is contained in:
Ajay 2022-10-29 21:03:34 -04:00
parent 96db571a5e
commit 571230db56
3 changed files with 9 additions and 1 deletions

View file

@ -136,7 +136,8 @@ addDefaults(config, {
},
disableOfflineQueue: true,
expiryTime: 24 * 60 * 60,
getTimeout: 40
getTimeout: 40,
maxConnections: 15000
},
redisRead: {
enabled: false,

View file

@ -5,6 +5,7 @@ interface RedisConfig extends redis.RedisClientOptions {
enabled: boolean;
expiryTime: number;
getTimeout: number;
maxConnections: number;
}
interface RedisReadOnlyConfig extends redis.RedisClientOptions {

View file

@ -41,7 +41,13 @@ if (config.redis?.enabled) {
const get = client.get.bind(client);
const getRead = readClient?.get?.bind(readClient);
exportClient.get = (key) => new Promise((resolve, reject) => {
if (activeRequests > config.redis.maxConnections) {
reject("Too many active requests");
return;
}
activeRequests++;
const timeout = config.redis.getTimeout ? setTimeout(() => reject(), config.redis.getTimeout) : null;
const chosenGet = pickChoice(get, getRead);
chosenGet(key).then((reply) => {