diff --git a/src/pdel.lua b/src/pdel.lua index a159a14..db36c45 100644 --- a/src/pdel.lua +++ b/src/pdel.lua @@ -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 diff --git a/test/integration/index.js b/test/integration/index.js index abd82b2..6471898 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -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)); });