Skip to content

Commit 77c2b55

Browse files
committed
fix an expired lock release script
1 parent afe5cf9 commit 77c2b55

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ const EXTEND_SCRIPT = `
4646
const RELEASE_SCRIPT = `
4747
local count = 0
4848
for i, key in ipairs(KEYS) do
49-
-- Only remove entries for *this* lock value.
50-
if redis.call("get", key) == ARGV[1] then
49+
local v = redis.call("get", key)
50+
if v == false then
51+
-- Key already missing/expired: treat as success.
52+
count = count + 1
53+
elseif v == ARGV[1] then
54+
-- Matches our lock value: delete and count as success.
5155
redis.pcall("del", key)
5256
count = count + 1
5357
end
5458
end
55-
56-
-- Return the number of entries removed.
59+
60+
-- Return the number of entries removed or already missing.
5761
return count
5862
`;
5963

0 commit comments

Comments
 (0)