Skip to content

Commit

Permalink
fix: case where there are zero matched keys (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 authored May 13, 2024
1 parent 0763ae1 commit 61c6d7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pdel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ if type(redis.replicate_commands) == "function" and redis.replicate_commands() t
repeat
cursor, keys = unpack(redis.call("SCAN", cursor, "MATCH", KEYS[1]))
count = count + #keys
redis.call("DEL", unpack(keys))
if #keys > 0 then
redis.call("DEL", unpack(keys))
end
until cursor == "0"

return count
else
local keys = redis.call("KEYS", KEYS[1])
redis.call("DEL", unpack(keys))
if #keys > 0 then
redis.call("DEL", unpack(keys))
end
return #keys
end
2 changes: 2 additions & 0 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ describe('integration', () => {
'bar:2',
])).to.become([null, null, 'val', 'val']); // eslint-disable-line unicorn/no-null
});

it('should delete zero keys', () => expect(redis.pdel('foo:*')).to.become(0));
});

0 comments on commit 61c6d7d

Please sign in to comment.