Fix redis set limiting

This commit is contained in:
Ajay
2022-11-19 23:32:09 -05:00
parent 849ca52ef8
commit 7bdcb10994

View File

@@ -86,7 +86,7 @@ if (config.redis?.enabled) {
const setFun = <T extends Array<any>>(func: (...args: T) => Promise<string>, params: T): Promise<string> => const setFun = <T extends Array<any>>(func: (...args: T) => Promise<string>, params: T): Promise<string> =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if (config.redis.maxWriteConnections && activeRequests > config.redis.maxWriteConnections) { if (config.redis.maxWriteConnections && activeRequests > config.redis.maxWriteConnections) {
reject("Too many active requests"); reject("Too many active requests to write");
return; return;
} }
@@ -108,8 +108,10 @@ if (config.redis?.enabled) {
}); });
}); });
// exportClient.set = (key, value) => setFun(client.set.bind(client), [key, value]); const set = client.set.bind(client);
// exportClient.setEx = (key, seconds, value) => setFun(client.setEx.bind(client), [key, seconds, value]); const setEx = client.setEx.bind(client);
exportClient.set = (key, value) => setFun(set, [key, value]);
exportClient.setEx = (key, seconds, value) => setFun(setEx, [key, seconds, value]);
exportClient.increment = (key) => new Promise((resolve, reject) => exportClient.increment = (key) => new Promise((resolve, reject) =>
void client.multi() void client.multi()
.incr(key) .incr(key)