Add max connection check to redis set

This commit is contained in:
Ajay 2022-11-07 22:51:26 -05:00
parent ee436d982c
commit 98f202f6a9

View file

@ -39,6 +39,7 @@ if (config.redis?.enabled) {
const get = client.get.bind(client);
const set = client.set.bind(client);
const getRead = readClient?.get?.bind(readClient);
exportClient.get = (key) => new Promise((resolve, reject) => {
if (activeRequests > config.redis.maxConnections) {
@ -66,6 +67,22 @@ if (config.redis?.enabled) {
reject(err);
});
});
exportClient.set = (key, value) => new Promise((resolve, reject) => {
if (activeRequests > config.redis.maxConnections) {
reject("Too many active requests");
return;
}
activeRequests++;
set(key, value).then((reply) => {
activeRequests--;
resolve(reply);
}).catch((err) => {
activeRequests--;
reject(err);
});
});
exportClient.increment = (key) => new Promise((resolve, reject) =>
void client.multi()
.incr(key)