mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-09-19 20:51:19 +02:00
Add active connection limit to setEx as well
This commit is contained in:
parent
0ead3892ba
commit
90e68caaf7
1 changed files with 24 additions and 20 deletions
|
@ -51,7 +51,6 @@ 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) {
|
||||
|
@ -83,7 +82,9 @@ if (config.redis?.enabled) {
|
|||
reject(err);
|
||||
});
|
||||
});
|
||||
exportClient.set = (key, value) => new Promise((resolve, reject) => {
|
||||
|
||||
const setFun = <T extends Array<any>>(func: (...args: T) => Promise<string> , params: T): Promise<string> =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (activeRequests > config.redis.maxWriteConnections) {
|
||||
reject("Too many active requests");
|
||||
return;
|
||||
|
@ -93,7 +94,7 @@ if (config.redis?.enabled) {
|
|||
activeRequests++;
|
||||
writeRequests++;
|
||||
|
||||
set(key, value).then((reply) => {
|
||||
func(...params).then((reply) => {
|
||||
activeRequests--;
|
||||
writeRequests--;
|
||||
resolve(reply);
|
||||
|
@ -106,6 +107,9 @@ if (config.redis?.enabled) {
|
|||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
exportClient.set = (key, value) => setFun(client.set.bind(client), [key, value]);
|
||||
exportClient.setEx = (key, seconds, value) => setFun(client.setEx.bind(client), [key, seconds, value]);
|
||||
exportClient.increment = (key) => new Promise((resolve, reject) =>
|
||||
void client.multi()
|
||||
.incr(key)
|
||||
|
|
Loading…
Reference in a new issue