Skip to content

Commit

Permalink
Handle delete of empty list of keys (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldsultan committed Jul 1, 2021
1 parent 7bb6b63 commit 01768da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/redis.rb
Expand Up @@ -555,6 +555,9 @@ def migrate(key, options)
# @param [String, Array<String>] keys
# @return [Integer] number of keys that were deleted
def del(*keys)
keys.flatten!(1)
return 0 if keys.empty?

synchronize do |client|
client.call([:del] + keys)
end
Expand Down
4 changes: 4 additions & 0 deletions test/commands_on_value_types_test.rb
Expand Up @@ -14,6 +14,8 @@ def test_del

assert_equal ["bar", "baz", "foo"], r.keys("*").sort

assert_equal 0, r.del("")

assert_equal 1, r.del("foo")

assert_equal ["bar", "baz"], r.keys("*").sort
Expand All @@ -30,6 +32,8 @@ def test_del_with_array_argument

assert_equal ["bar", "baz", "foo"], r.keys("*").sort

assert_equal 0, r.del([])

assert_equal 1, r.del(["foo"])

assert_equal ["bar", "baz"], r.keys("*").sort
Expand Down

0 comments on commit 01768da

Please sign in to comment.