mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
add pipeline delete keys
This commit is contained in:
parent
4b15494107
commit
c87940251e
|
|
@ -23,7 +23,11 @@ export const refreshVersionKey = async (key: `${SystemCacheKeyEnum}`, id?: strin
|
|||
const pattern = `${cachePrefix}${key}`;
|
||||
const keys = await getAllKeysByPrefix(pattern);
|
||||
if (keys.length > 0) {
|
||||
await redis.del(keys);
|
||||
const pipeline = redis.pipeline();
|
||||
for (const k of keys) {
|
||||
pipeline.del(k);
|
||||
}
|
||||
await pipeline.exec();
|
||||
}
|
||||
} else {
|
||||
await redis.set(versionKey, val);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export const getAllKeysByPrefix = async (key: string) => {
|
|||
cursor = nextCursor;
|
||||
|
||||
for (const k of keys) {
|
||||
results.push(key.replace(FASTGPT_REDIS_PREFIX, ''));
|
||||
results.push(k.replace(FASTGPT_REDIS_PREFIX, ''));
|
||||
}
|
||||
} while (cursor !== '0');
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,12 @@ const createMockRedisClient = () => ({
|
|||
del: vi.fn().mockResolvedValue(1),
|
||||
exists: vi.fn().mockResolvedValue(0),
|
||||
keys: vi.fn().mockResolvedValue([]),
|
||||
scan: vi.fn().mockResolvedValue(['0', []]),
|
||||
scan: vi.fn().mockImplementation((cursor) => {
|
||||
// 模拟多次迭代的场景
|
||||
if (cursor === '0') return ['100', ['key1', 'key2']];
|
||||
if (cursor === '100') return ['0', ['key3']];
|
||||
return ['0', []];
|
||||
}),
|
||||
|
||||
// Hash operations
|
||||
hget: vi.fn().mockResolvedValue(null),
|
||||
|
|
|
|||
Loading…
Reference in New Issue