Skip to content

Commit 0adfab9

Browse files
committed
fix: lua script edge case
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 21e42bf commit 0adfab9

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

services/libs/redis/src/cache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ return cjson.encode(results)`
218218
// Guard clause: Redis errors if you call SREM with no members
219219
if (members.length === 0) return 0
220220

221-
// Uses 'unpack' for O(1) script execution instead of a loop
222221
const script = `
223-
redis.call('SREM', KEYS[1], unpack(ARGV, 2))
222+
local chunkSize = 500
223+
for i = 2, #ARGV, chunkSize do
224+
redis.call('SREM', KEYS[1], unpack(ARGV, i, math.min(i + chunkSize - 1, #ARGV)))
225+
end
226+
224227
if redis.call('SCARD', KEYS[1]) == 0 then
225228
return redis.call('SREM', KEYS[2], ARGV[1])
226229
end

0 commit comments

Comments
 (0)