diff --git a/src/utils/redis.ts b/src/utils/redis.ts index 49d7ed0..900d0fb 100644 --- a/src/utils/redis.ts +++ b/src/utils/redis.ts @@ -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)