@@ -127,8 +127,7 @@ def call_once(*command, **kwargs)
127
127
end
128
128
129
129
def blocking_call ( timeout , *command , **kwargs )
130
- node = assign_node ( *command )
131
- try_send ( node , :blocking_call , timeout , *command , **kwargs )
130
+ send_command ( :blocking_call , timeout , *command , **kwargs )
132
131
end
133
132
134
133
def scan ( *args , **kwargs , &block )
@@ -186,41 +185,43 @@ def fetch_cluster_info!(config, pool: nil, **kwargs)
186
185
node_info : node_info , pool : pool , with_replica : config . use_replica? , **kwargs )
187
186
end
188
187
189
- def send_command ( method , *command , **kwargs , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
188
+ def send_command ( method , *args , **kwargs , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
189
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
190
+
190
191
cmd = command . first . to_s . downcase
191
192
case cmd
192
193
when 'acl' , 'auth' , 'bgrewriteaof' , 'bgsave' , 'quit' , 'save'
193
- @node . call_all ( method , *command , **kwargs , &block ) . first
194
+ @node . call_all ( method , *args , **kwargs , &block ) . first
194
195
when 'flushall' , 'flushdb'
195
- @node . call_primaries ( method , *command , **kwargs , &block ) . first
196
- when 'ping' then @node . send_ping ( method , *command , **kwargs , &block ) . first
197
- when 'wait' then send_wait_command ( method , *command , **kwargs , &block )
198
- when 'keys' then @node . call_replicas ( method , *command , **kwargs , &block ) . flatten . sort
199
- when 'dbsize' then @node . call_replicas ( method , *command , **kwargs , &block ) . sum
196
+ @node . call_primaries ( method , *args , **kwargs , &block ) . first
197
+ when 'ping' then @node . send_ping ( method , *args , **kwargs , &block ) . first
198
+ when 'wait' then send_wait_command ( method , *args , **kwargs , &block )
199
+ when 'keys' then @node . call_replicas ( method , *args , **kwargs , &block ) . flatten . sort
200
+ when 'dbsize' then @node . call_replicas ( method , *args , **kwargs , &block ) . sum
200
201
when 'scan' then _scan ( *command , **kwargs )
201
- when 'lastsave' then @node . call_all ( method , *command , **kwargs , &block ) . sort
202
- when 'role' then @node . call_all ( method , *command , **kwargs , &block )
203
- when 'config' then send_config_command ( method , *command , **kwargs , &block )
204
- when 'client' then send_client_command ( method , *command , **kwargs , &block )
205
- when 'cluster' then send_cluster_command ( method , *command , **kwargs , &block )
202
+ when 'lastsave' then @node . call_all ( method , *args , **kwargs , &block ) . sort
203
+ when 'role' then @node . call_all ( method , *args , **kwargs , &block )
204
+ when 'config' then send_config_command ( method , *args , **kwargs , &block )
205
+ when 'client' then send_client_command ( method , *args , **kwargs , &block )
206
+ when 'cluster' then send_cluster_command ( method , *args , **kwargs , &block )
206
207
when 'readonly' , 'readwrite' , 'shutdown'
207
208
raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported , cmd
208
- when 'memory' then send_memory_command ( method , *command , **kwargs , &block )
209
- when 'script' then send_script_command ( method , *command , **kwargs , &block )
210
- when 'pubsub' then send_pubsub_command ( method , *command , **kwargs , &block )
209
+ when 'memory' then send_memory_command ( method , *args , **kwargs , &block )
210
+ when 'script' then send_script_command ( method , *args , **kwargs , &block )
211
+ when 'pubsub' then send_pubsub_command ( method , *args , **kwargs , &block )
211
212
when 'discard' , 'exec' , 'multi' , 'unwatch'
212
213
raise ::RedisClient ::Cluster ::AmbiguousNodeError , cmd
213
214
else
214
215
node = assign_node ( *command )
215
- try_send ( node , method , *command , **kwargs , &block )
216
+ try_send ( node , method , *args , **kwargs , &block )
216
217
end
217
218
rescue RedisClient ::Cluster ::Node ::ReloadNeeded
218
219
update_cluster_info!
219
220
raise ::RedisClient ::Cluster ::NodeMightBeDown
220
221
end
221
222
222
- def send_wait_command ( method , *command , retry_count : 3 , **kwargs , &block )
223
- @node . call_primaries ( method , *command , **kwargs , &block ) . sum
223
+ def send_wait_command ( method , *args , retry_count : 3 , **kwargs , &block )
224
+ @node . call_primaries ( method , *args , **kwargs , &block ) . sum
224
225
rescue RedisClient ::Cluster ::ErrorCollection => e
225
226
raise if retry_count <= 0
226
227
raise if e . errors . values . none? do |err |
@@ -232,64 +233,76 @@ def send_wait_command(method, *command, retry_count: 3, **kwargs, &block)
232
233
retry
233
234
end
234
235
235
- def send_config_command ( method , *command , **kwargs , &block )
236
+ def send_config_command ( method , *args , **kwargs , &block )
237
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
238
+
236
239
case command [ 1 ] . to_s . downcase
237
240
when 'resetstat' , 'rewrite' , 'set'
238
- @node . call_all ( method , *command , **kwargs , &block ) . first
239
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
241
+ @node . call_all ( method , *args , **kwargs , &block ) . first
242
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
240
243
end
241
244
end
242
245
243
- def send_memory_command ( method , *command , **kwargs , &block )
246
+ def send_memory_command ( method , *args , **kwargs , &block )
247
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
248
+
244
249
case command [ 1 ] . to_s . downcase
245
- when 'stats' then @node . call_all ( method , *command , **kwargs , &block )
246
- when 'purge' then @node . call_all ( method , *command , **kwargs , &block ) . first
247
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
250
+ when 'stats' then @node . call_all ( method , *args , **kwargs , &block )
251
+ when 'purge' then @node . call_all ( method , *args , **kwargs , &block ) . first
252
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
248
253
end
249
254
end
250
255
251
- def send_client_command ( method , *command , **kwargs , &block )
256
+ def send_client_command ( method , *args , **kwargs , &block )
257
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
258
+
252
259
case command [ 1 ] . to_s . downcase
253
- when 'list' then @node . call_all ( method , *command , **kwargs , &block ) . flatten
260
+ when 'list' then @node . call_all ( method , *args , **kwargs , &block ) . flatten
254
261
when 'pause' , 'reply' , 'setname'
255
- @node . call_all ( method , *command , **kwargs , &block ) . first
256
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
262
+ @node . call_all ( method , *args , **kwargs , &block ) . first
263
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
257
264
end
258
265
end
259
266
260
- def send_cluster_command ( method , *command , **kwargs , &block ) # rubocop:disable Metrics/MethodLength
267
+ def send_cluster_command ( method , *args , **kwargs , &block ) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
268
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
261
269
subcommand = command [ 1 ] . to_s . downcase
270
+
262
271
case subcommand
263
272
when 'addslots' , 'delslots' , 'failover' , 'forget' , 'meet' , 'replicate' ,
264
273
'reset' , 'set-config-epoch' , 'setslot'
265
274
raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported , [ 'cluster' , subcommand ]
266
- when 'saveconfig' then @node . call_all ( method , *command , **kwargs , &block ) . first
275
+ when 'saveconfig' then @node . call_all ( method , *args , **kwargs , &block ) . first
267
276
when 'getkeysinslot'
268
277
raise ArgumentError , command . join ( ' ' ) if command . size != 4
269
278
270
- find_node ( @node . find_node_key_of_replica ( command [ 2 ] ) ) . send ( method , *command , **kwargs , &block )
271
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
279
+ find_node ( @node . find_node_key_of_replica ( command [ 2 ] ) ) . send ( method , *args , **kwargs , &block )
280
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
272
281
end
273
282
end
274
283
275
- def send_script_command ( method , *command , **kwargs , &block )
284
+ def send_script_command ( method , *args , **kwargs , &block )
285
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
286
+
276
287
case command [ 1 ] . to_s . downcase
277
288
when 'debug' , 'kill'
278
- @node . call_all ( method , *command , **kwargs , &block ) . first
289
+ @node . call_all ( method , *args , **kwargs , &block ) . first
279
290
when 'flush' , 'load'
280
- @node . call_primaries ( method , *command , **kwargs , &block ) . first
281
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
291
+ @node . call_primaries ( method , *args , **kwargs , &block ) . first
292
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
282
293
end
283
294
end
284
295
285
- def send_pubsub_command ( method , *command , **kwargs , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
296
+ def send_pubsub_command ( method , *args , **kwargs , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
297
+ command = method == :blocking_call && args . size > 1 ? args [ 1 ..] : args
298
+
286
299
case command [ 1 ] . to_s . downcase
287
- when 'channels' then @node . call_all ( method , *command , **kwargs , &block ) . flatten . uniq . sort
300
+ when 'channels' then @node . call_all ( method , *args , **kwargs , &block ) . flatten . uniq . sort
288
301
when 'numsub'
289
- @node . call_all ( method , *command , **kwargs , &block ) . reject ( &:empty? ) . map { |e | Hash [ *e ] }
302
+ @node . call_all ( method , *args , **kwargs , &block ) . reject ( &:empty? ) . map { |e | Hash [ *e ] }
290
303
. reduce ( { } ) { |a , e | a . merge ( e ) { |_ , v1 , v2 | v1 + v2 } }
291
- when 'numpat' then @node . call_all ( method , *command , **kwargs , &block ) . sum
292
- else assign_node ( *command ) . send ( method , *command , **kwargs , &block )
304
+ when 'numpat' then @node . call_all ( method , *args , **kwargs , &block ) . sum
305
+ else assign_node ( *command ) . send ( method , *args , **kwargs , &block )
293
306
end
294
307
end
295
308
0 commit comments