mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 17:08:35 +03:00
Back rate limit by redia and upgrade node-redis
This commit is contained in:
@@ -18,18 +18,19 @@ export async function getHashCache<T extends string>(value: T, times = defaulted
|
||||
|
||||
async function getFromRedis<T extends string>(key: HashedValue): Promise<T & HashedValue> {
|
||||
const redisKey = shaHashKey(key);
|
||||
const { err, reply } = await redis.getAsync(redisKey);
|
||||
|
||||
if (!err && reply) {
|
||||
try {
|
||||
try {
|
||||
const reply = await redis.get(redisKey);;
|
||||
|
||||
if (reply) {
|
||||
Logger.debug(`Got data from redis: ${reply}`);
|
||||
return reply as T & HashedValue;
|
||||
} catch (e) {
|
||||
// If all else, continue on hashing
|
||||
}
|
||||
}
|
||||
const data = getHash(key, cachedHashTimes);
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
// Otherwise, calculate it
|
||||
const data = getHash(key, cachedHashTimes);
|
||||
redis.set(key, data);
|
||||
|
||||
redis.setAsync(key, data);
|
||||
return data as T & HashedValue;
|
||||
}
|
||||
Reference in New Issue
Block a user