perf: replace redis KEYS with SCAN (#6101)

* perf: replace redis KEYS with SCAN

* test: add redis scan mock to fix unit tests

* Fix formatting in redis.ts mock functions

* fix comment word

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
lgphone
2025-12-18 10:37:09 +08:00
committed by GitHub
parent 09b9fa517b
commit 342aca0b21
3 changed files with 75 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ const createMockRedisClient = () => ({
del: vi.fn().mockResolvedValue(1),
exists: vi.fn().mockResolvedValue(0),
keys: vi.fn().mockResolvedValue([]),
scan: vi.fn().mockResolvedValue(['0', []]),
// Hash operations
hget: vi.fn().mockResolvedValue(null),
@@ -53,7 +54,14 @@ const createMockRedisClient = () => ({
sadd: vi.fn().mockResolvedValue(1),
srem: vi.fn().mockResolvedValue(1),
smembers: vi.fn().mockResolvedValue([]),
sismember: vi.fn().mockResolvedValue(0)
sismember: vi.fn().mockResolvedValue(0),
// pipeline
pipeline: vi.fn(() => ({
del: vi.fn().mockReturnThis(),
unlink: vi.fn().mockReturnThis(),
exec: vi.fn().mockResolvedValue([])
}))
});
// Mock Redis connections to prevent connection errors in tests