@@ -49,20 +49,20 @@ def test_parse_command_reply
49
49
[
50
50
{
51
51
rows : [
52
- [ 'get' , 2 , Set [ 'readonly' , 'fast' ] , 1 , 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ] ,
53
- [ 'set' , -3 , Set [ 'write' , 'denyoom' , 'movablekeys' ] , 1 , 1 , 1 , Set [ '@write' , '@string' , '@slow' ] , Set [ ] , Set [ ] , Set [ ] ]
52
+ [ 'get' , 2 , Set [ 'readonly' , 'fast' ] , 1 , - 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ] ,
53
+ [ 'set' , -3 , Set [ 'write' , 'denyoom' , 'movablekeys' ] , 1 , - 1 , 2 , Set [ '@write' , '@string' , '@slow' ] , Set [ ] , Set [ ] , Set [ ] ]
54
54
] ,
55
55
want : {
56
- 'get' => { first_key_position : 1 , write? : false , readonly? : true } ,
57
- 'set' => { first_key_position : 1 , write? : true , readonly? : false }
56
+ 'get' => { first_key_position : 1 , last_key_position : - 1 , key_step : 1 , write? : false , readonly? : true } ,
57
+ 'set' => { first_key_position : 1 , last_key_position : - 1 , key_step : 2 , write? : true , readonly? : false }
58
58
}
59
59
} ,
60
60
{
61
61
rows : [
62
- [ 'GET' , 2 , Set [ 'readonly' , 'fast' ] , 1 , 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ]
62
+ [ 'GET' , 2 , Set [ 'readonly' , 'fast' ] , 1 , - 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ]
63
63
] ,
64
64
want : {
65
- 'get' => { first_key_position : 1 , write? : false , readonly? : true }
65
+ 'get' => { first_key_position : 1 , last_key_position : - 1 , key_step : 1 , write? : false , readonly? : true }
66
66
}
67
67
} ,
68
68
{ rows : [ [ ] ] , want : { } } ,
@@ -190,6 +190,37 @@ def test_determine_optional_key_position
190
190
assert_equal ( c [ :want ] , got , msg )
191
191
end
192
192
end
193
+
194
+ def test_extract_all_keys
195
+ cmd = ::RedisClient ::Cluster ::Command . load ( @raw_clients )
196
+ [
197
+ { command : [ 'EVAL' , 'return ARGV[1]' , '0' , 'hello' ] , want : [ ] } ,
198
+ { command : [ 'EVAL' , 'return ARGV[1]' , '3' , 'key1' , 'key2' , 'key3' , 'arg1' , 'arg2' ] , want : %w[ key1 key2 key3 ] } ,
199
+ { command : [ [ 'EVAL' ] , '"return ARGV[1]"' , 0 , 'hello' ] , want : [ ] } ,
200
+ { command : %w[ EVALSHA sha1 2 foo bar baz zap ] , want : %w[ foo bar ] } ,
201
+ { command : %w[ MIGRATE host port key 0 5 COPY ] , want : %w[ key ] } ,
202
+ { command : [ 'MIGRATE' , 'host' , 'port' , '' , '0' , '5' , 'COPY' , 'KEYS' , 'key1' ] , want : %w[ key1 ] } ,
203
+ { command : [ 'MIGRATE' , 'host' , 'port' , '' , '0' , '5' , 'COPY' , 'KEYS' , 'key1' , 'key2' ] , want : %w[ key1 key2 ] } ,
204
+ { command : %w[ ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 ] , want : %w[ zset1 zset2 ] } ,
205
+ { command : %w[ ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3 ] , want : %w[ zset1 zset2 ] } ,
206
+ { command : %w[ OBJECT HELP ] , want : [ ] } ,
207
+ { command : %w[ MEMORY HELP ] , want : [ ] } ,
208
+ { command : %w[ MEMORY USAGE key ] , want : %w[ key ] } ,
209
+ { command : %w[ XREAD COUNT 2 STREAMS mystream writers 0-0 0-0 ] , want : %w[ mystream writers ] } ,
210
+ { command : %w[ XREADGROUP GROUP group consumer STREAMS key id ] , want : %w[ key ] } ,
211
+ { command : %w[ SET foo 1 ] , want : %w[ foo ] } ,
212
+ { command : %w[ set foo 1 ] , want : %w[ foo ] } ,
213
+ { command : [ [ 'SET' ] , 'foo' , 1 ] , want : %w[ foo ] } ,
214
+ { command : %w[ GET foo ] , want : %w[ foo ] } ,
215
+ { command : %w[ MGET foo bar baz ] , want : %w[ foo bar baz ] } ,
216
+ { command : %w[ MSET foo val bar val baz val ] , want : %w[ foo bar baz ] } ,
217
+ { command : %w[ BLPOP foo bar 0 ] , want : %w[ foo bar ] }
218
+ ] . each_with_index do |c , idx |
219
+ msg = "Case: #{ idx } "
220
+ got = cmd . send ( :extract_all_keys , c [ :command ] )
221
+ assert_equal ( c [ :want ] , got , msg )
222
+ end
223
+ end
193
224
end
194
225
end
195
226
end
0 commit comments