Navigation Menu

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

Conversation

haroldsultan
Copy link
Contributor

Handle deletion of an empty list of keys

@haroldsultan
Copy link
Contributor Author

Please advise as to how to test. Thanks

lib/redis.rb Outdated
Comment on lines 558 to 560
if keys.is_a?(Array) && keys.empty?
return 0
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if keys.is_a?(Array) && keys.empty?
return 0
end
return 0 if keys.empty?

keys can't be anything else than an array.

@byroot
Copy link
Collaborator

byroot commented Jul 1, 2021

Please advise as to how to test. Thanks

def test_del
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal 1, r.del("foo")
assert_equal ["bar", "baz"], r.keys("*").sort
assert_equal 2, r.del("bar", "baz")
assert_equal [], r.keys("*").sort
end

@haroldsultan haroldsultan requested a review from byroot July 1, 2021 15:58
@@ -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)

@haroldsultan haroldsultan requested a review from byroot July 1, 2021 19:18
@byroot byroot merged commit 01768da into redis:master Jul 1, 2021
@haroldsultan
Copy link
Contributor Author

Thanks @byroot for the review and feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants