Skip to content

Commit ff4a3f7

Browse files
#hscan returns an array of key/value pairs
1 parent 80b7038 commit ff4a3f7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/redis.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,9 +2322,11 @@ def scan(cursor, options={})
23222322
# - `:match => String`: only return keys matching the pattern
23232323
# - `:count => Integer`: return count keys at most per iteration
23242324
#
2325-
# @return [String, Array<String>] the next cursor and all found keys
2325+
# @return [String, Array<[String, String]>] the next cursor and all found keys
23262326
def hscan(key, cursor, options={})
2327-
_scan(:hscan, cursor, options.merge(:key => key))
2327+
_scan(:hscan, cursor, options.merge(:key => key)) do |reply|
2328+
[reply[0], reply[1].each_slice(2).to_a]
2329+
end
23282330
end
23292331

23302332
# Scan a sorted set

test/scanning_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ def test_hscan_with_encoding
9898
assert_equal enc.to_s, r.object("encoding", "hash")
9999

100100
cursor = 0
101-
all_keys = []
101+
all_key_values = []
102102
loop {
103-
cursor, keys = r.hscan "hash", cursor
104-
all_keys += keys
103+
cursor, key_values = r.hscan "hash", cursor
104+
all_key_values.concat key_values
105105
break if cursor == "0"
106106
}
107107

108108
keys2 = []
109-
all_keys.each_slice(2) do |k, v|
109+
all_key_values.each do |k, v|
110110
assert_equal "key:#{v}", k
111111
keys2 << k
112112
end

0 commit comments

Comments
 (0)