Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle delete of empty list of keys #998

Merged
merged 6 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/redis.rb
Expand Up @@ -555,6 +555,8 @@ def migrate(key, options)
# @param [String, Array<String>] keys
# @return [Integer] number of keys that were deleted
def del(*keys)
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([])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't handled by your code, you need to add a keys.flatten! in del.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even flatten!(1)


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

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