Avoid calling redis.del with empty array (#1167)

This commit is contained in:
Dotan Simha 2023-01-29 09:52:33 +01:00 committed by GitHub
parent 4ed268c86a
commit 6d2f3d3e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,9 @@ function useSafeRedis(redis: Redis, logger: FastifyLoggerInstance) {
}
if (redis.status === 'ready') {
await redis.del(...keys);
if (keys.length > 0) {
await redis.del(...keys);
}
} else {
logger.warn('Redis is not ready, skipping DEL');
}
@ -113,7 +115,9 @@ export function useCache(
async function invalidateTokens(hashedTokens: string[]) {
cacheInvalidations.inc(1);
await redis.del(hashedTokens.map(generateKey));
if (hashedTokens.length > 0) {
await redis.del(hashedTokens.map(generateKey));
}
}
// Thanks to the `atomic` function, every call to this function will only be executed once and Promise will be shared.