diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index 913258f05..c9cac7394 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -1,6 +1,7 @@ import { redisClient } from "@/db/redis.js"; import { encode, decode } from "msgpackr"; import { ChainableCommander } from "ioredis"; +import config from "@/config/index.js"; export class Cache { private ttl: number; @@ -37,12 +38,14 @@ export class Cache { } public async getAll(renew = false): Promise> { - const keys = await redisClient.keys(`${this.prefix}*`); + const finalPrefix = `${config.cacheServer?.prefix ?? config.redis.prefix}:${this.prefix}:`; + const keys = (await redisClient.keys(`${finalPrefix}*`)).map(p => p.substring(finalPrefix.length)); + const prefixedKeys = keys.map(p => this.prefixedKey(p)); const map = new Map(); if (keys.length === 0) { return map; } - const values = await redisClient.mgetBuffer(keys); + const values = await redisClient.mgetBuffer(prefixedKeys); for (const [i, key] of keys.entries()) { const val = values[i]; @@ -54,7 +57,7 @@ export class Cache { if (renew) { const trans = redisClient.multi(); for (const key of map.keys()) { - trans.expire(key, this.ttl); + trans.expire(this.prefixedKey(key), this.ttl); } await trans.exec(); } @@ -64,7 +67,7 @@ export class Cache { public async delete(...keys: (string | null)[]): Promise { if (keys.length > 0) { - const _keys = keys.map(this.prefixedKey); + const _keys = keys.map(p => this.prefixedKey(p)); await redisClient.del(_keys); } }