From dd19496227431b8179d51419a778752da000af41 Mon Sep 17 00:00:00 2001 From: sanny-io Date: Sun, 19 Jul 2026 00:35:42 +0000 Subject: [PATCH 1/2] fix: Redis `invalidate` not working when there is only 1 entry --- src/providers/redis.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/redis.ts b/src/providers/redis.ts index 704eaa4..b58093a 100644 --- a/src/providers/redis.ts +++ b/src/providers/redis.ts @@ -60,7 +60,7 @@ export class RedisCacheProvider implements CacheProvider { }) stream.on('data', async (keys: string[]) => { - if (keys.length > 1) { + if (keys.length > 0) { await this.redis.del(...keys) } }) @@ -81,7 +81,7 @@ export class RedisCacheProvider implements CacheProvider { }) stream.on('data', async (keys: string[]) => { - if (keys.length > 1) { + if (keys.length > 0) { await this.redis.del(...keys) } }) From d70dae04265be96c3211a27a5beb4521b3199f3b Mon Sep 17 00:00:00 2001 From: sanny-io Date: Sun, 19 Jul 2026 00:36:56 +0000 Subject: [PATCH 2/2] chore: add test --- tests/redis.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/redis.test.ts b/tests/redis.test.ts index a4a8c71..be852d1 100644 --- a/tests/redis.test.ts +++ b/tests/redis.test.ts @@ -1191,4 +1191,40 @@ describe('Cache plugin (redis)', () => { }), ).resolves.toBe(true) }) + + it('invalidates correctly when there is only 1 entry', async () => { + let extDb = db.$use( + defineCachePlugin({ + provider: new RedisCacheProvider({ + url: process.env['REDIS_URL'] as string, + }), + }), + ) + + await extDb.user.create({ + data: { + email: 'test@email.com', + }, + }) + + await extDb.user.exists({ + cache: { + tags: ['user1'], + ttl: 60, + }, + }) + + await extDb.$cache.invalidate({ + tags: ['user1'], + }) + + await extDb.user.exists({ + cache: { + tags: ['user1'], + ttl: 60, + }, + }) + + expect(extDb.$cache.status).toBe('miss') + }) })