@@ -2638,12 +2638,13 @@ def evalsha(*args)
2638
2638
_eval ( :evalsha , args )
2639
2639
end
2640
2640
2641
- def _scan ( command , cursor , args , match : nil , count : nil , &block )
2641
+ def _scan ( command , cursor , args , match : nil , count : nil , type : nil , &block )
2642
2642
# SSCAN/ZSCAN/HSCAN already prepend the key to +args+.
2643
2643
2644
2644
args << cursor
2645
2645
args << "MATCH" << match if match
2646
2646
args << "COUNT" << count if count
2647
+ args << "TYPE" << type if type
2647
2648
2648
2649
synchronize do |client |
2649
2650
client . call ( [ command ] + args , &block )
@@ -2658,11 +2659,15 @@ def _scan(command, cursor, args, match: nil, count: nil, &block)
2658
2659
# @example Retrieve a batch of keys matching a pattern
2659
2660
# redis.scan(4, :match => "key:1?")
2660
2661
# # => ["92", ["key:13", "key:18"]]
2662
+ # @example Retrieve a batch of keys of a certain type
2663
+ # redis.scan(92, :type => "zset")
2664
+ # # => ["173", ["sortedset:14", "sortedset:78"]]
2661
2665
#
2662
2666
# @param [String, Integer] cursor the cursor of the iteration
2663
2667
# @param [Hash] options
2664
2668
# - `:match => String`: only return keys matching the pattern
2665
2669
# - `:count => Integer`: return count keys at most per iteration
2670
+ # - `:type => String`: return keys only of the given type
2666
2671
#
2667
2672
# @return [String, Array<String>] the next cursor and all found keys
2668
2673
def scan ( cursor , **options )
@@ -2678,10 +2683,15 @@ def scan(cursor, **options)
2678
2683
# redis.scan_each(:match => "key:1?") {|key| puts key}
2679
2684
# # => key:13
2680
2685
# # => key:18
2686
+ # @example Execute block for each key of a type
2687
+ # redis.scan_each(:type => "hash") {|key| puts redis.type(key)}
2688
+ # # => "hash"
2689
+ # # => "hash"
2681
2690
#
2682
2691
# @param [Hash] options
2683
2692
# - `:match => String`: only return keys matching the pattern
2684
2693
# - `:count => Integer`: return count keys at most per iteration
2694
+ # - `:type => String`: return keys only of the given type
2685
2695
#
2686
2696
# @return [Enumerator] an enumerator for all found keys
2687
2697
def scan_each ( **options , &block )
0 commit comments