@@ -62,30 +62,37 @@ def blocking_call_v(timeout, command, &block)
6262 end
6363
6464 def scan ( *args , **kwargs , &block )
65- raise ArgumentError , 'block required' unless block
65+ return to_enum ( __callee__ , * args , ** kwargs ) unless block_given?
6666
67+ command = @command_builder . generate ( [ 'SCAN' , ZERO_CURSOR_FOR_SCAN ] + args , kwargs )
6768 seed = Random . new_seed
68- cursor = ZERO_CURSOR_FOR_SCAN
6969 loop do
70- cursor , keys = router . scan ( 'SCAN' , cursor , *args , seed : seed , **kwargs )
70+ cursor , keys = router . scan ( command , seed : seed )
71+ command [ 1 ] = cursor
7172 keys . each ( &block )
7273 break if cursor == ZERO_CURSOR_FOR_SCAN
7374 end
7475 end
7576
7677 def sscan ( key , *args , **kwargs , &block )
77- node = router . assign_node ( [ 'SSCAN' , key ] )
78- router . try_delegate ( node , :sscan , key , *args , **kwargs , &block )
78+ return to_enum ( __callee__ , key , *args , **kwargs ) unless block_given?
79+
80+ command = @command_builder . generate ( [ 'SSCAN' , key , ZERO_CURSOR_FOR_SCAN ] + args , kwargs )
81+ router . scan_single_key ( command , arity : 1 , &block )
7982 end
8083
8184 def hscan ( key , *args , **kwargs , &block )
82- node = router . assign_node ( [ 'HSCAN' , key ] )
83- router . try_delegate ( node , :hscan , key , *args , **kwargs , &block )
85+ return to_enum ( __callee__ , key , *args , **kwargs ) unless block_given?
86+
87+ command = @command_builder . generate ( [ 'HSCAN' , key , ZERO_CURSOR_FOR_SCAN ] + args , kwargs )
88+ router . scan_single_key ( command , arity : 2 , &block )
8489 end
8590
8691 def zscan ( key , *args , **kwargs , &block )
87- node = router . assign_node ( [ 'ZSCAN' , key ] )
88- router . try_delegate ( node , :zscan , key , *args , **kwargs , &block )
92+ return to_enum ( __callee__ , key , *args , **kwargs ) unless block_given?
93+
94+ command = @command_builder . generate ( [ 'ZSCAN' , key , ZERO_CURSOR_FOR_SCAN ] + args , kwargs )
95+ router . scan_single_key ( command , arity : 2 , &block )
8996 end
9097
9198 def pipelined ( exception : true )
0 commit comments