@@ -2271,7 +2271,7 @@ def evalsha(*args)
2271
2271
_eval ( :evalsha , args )
2272
2272
end
2273
2273
2274
- def _scan ( command , cursor , options = { } )
2274
+ def _scan ( command , cursor , options = { } , & block )
2275
2275
# SSCAN/ZSCAN/HSCAN need a key to work on
2276
2276
args = [ ]
2277
2277
@@ -2289,7 +2289,7 @@ def _scan(command, cursor, options = {})
2289
2289
args . concat ( [ "COUNT" , count ] ) if count
2290
2290
2291
2291
synchronize do |client |
2292
- client . call ( [ command ] + args )
2292
+ client . call ( [ command ] + args , & block )
2293
2293
end
2294
2294
end
2295
2295
@@ -2322,9 +2322,11 @@ def scan(cursor, options={})
2322
2322
# - `:match => String`: only return keys matching the pattern
2323
2323
# - `:count => Integer`: return count keys at most per iteration
2324
2324
#
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
2326
2326
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
2328
2330
end
2329
2331
2330
2332
# Scan a sorted set
@@ -2337,9 +2339,12 @@ def hscan(key, cursor, options={})
2337
2339
# - `:match => String`: only return keys matching the pattern
2338
2340
# - `:count => Integer`: return count keys at most per iteration
2339
2341
#
2340
- # @return [String, Array<String>] the next cursor and all found scores and members
2342
+ # @return [String, Array<[String, Float]>] the next cursor and all found
2343
+ # members and scores
2341
2344
def zscan ( key , cursor , options = { } )
2342
- _scan ( :zscan , cursor , options . merge ( :key => key ) )
2345
+ _scan ( :zscan , cursor , options . merge ( :key => key ) ) do |reply |
2346
+ [ reply [ 0 ] , reply [ 1 ] . each_slice ( 2 ) . map { |k , s | [ k , _floatify ( s ) ] } ]
2347
+ end
2343
2348
end
2344
2349
2345
2350
# Scan a set
0 commit comments