mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Add max connection check to redis set
This commit is contained in:
@@ -39,6 +39,7 @@ if (config.redis?.enabled) {
|
|||||||
|
|
||||||
|
|
||||||
const get = client.get.bind(client);
|
const get = client.get.bind(client);
|
||||||
|
const set = client.set.bind(client);
|
||||||
const getRead = readClient?.get?.bind(readClient);
|
const getRead = readClient?.get?.bind(readClient);
|
||||||
exportClient.get = (key) => new Promise((resolve, reject) => {
|
exportClient.get = (key) => new Promise((resolve, reject) => {
|
||||||
if (activeRequests > config.redis.maxConnections) {
|
if (activeRequests > config.redis.maxConnections) {
|
||||||
@@ -66,6 +67,22 @@ if (config.redis?.enabled) {
|
|||||||
reject(err);
|
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) =>
|
exportClient.increment = (key) => new Promise((resolve, reject) =>
|
||||||
void client.multi()
|
void client.multi()
|
||||||
.incr(key)
|
.incr(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user