mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Add max connection check to redis set
This commit is contained in:
parent
ee436d982c
commit
98f202f6a9
1 changed files with 17 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue