Skip to content

Commit dde484f

Browse files
authored
Merge pull request #755 from byroot/hdel-splat
Super splat args for HDEL
2 parents 891d166 + 8ff1065 commit dde484f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/redis.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,9 @@ def mapped_hmget(key, *fields)
21022102
# @param [String] key
21032103
# @param [String, Array<String>] field
21042104
# @return [Fixnum] the number of fields that were removed from the hash
2105-
def hdel(key, field)
2105+
def hdel(key, *fields)
21062106
synchronize do |client|
2107-
client.call([:hdel, key, field])
2107+
client.call([:hdel, key, *fields])
21082108
end
21092109
end
21102110

lib/redis/distributed.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ def mapped_hmget(key, *fields)
692692
end
693693

694694
# Delete one or more hash fields.
695-
def hdel(key, field)
696-
node_for(key).hdel(key, field)
695+
def hdel(key, *fields)
696+
node_for(key).hdel(key, *fields)
697697
end
698698

699699
# Determine if a hash field exists.

test/lint/hashes.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ def test_hdel
3030
assert_equal nil, r.hget("foo", "f1")
3131
end
3232

33+
def test_splat_hdel
34+
target_version "2.3.9" do
35+
r.hset("foo", "f1", "s1")
36+
r.hset("foo", "f2", "s2")
37+
38+
assert_equal "s1", r.hget("foo", "f1")
39+
assert_equal "s2", r.hget("foo", "f2")
40+
41+
assert_equal 2, r.hdel("foo", "f1", "f2")
42+
43+
assert_equal nil, r.hget("foo", "f1")
44+
assert_equal nil, r.hget("foo", "f2")
45+
end
46+
end
47+
3348
def test_variadic_hdel
3449
target_version "2.3.9" do
3550
r.hset("foo", "f1", "s1")

0 commit comments

Comments
 (0)