@@ -127,8 +127,7 @@ def call_once(*command, **kwargs)
127127 end
128128
129129 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 )
132131 end
133132
134133 def scan ( *args , **kwargs , &block )
@@ -186,41 +185,43 @@ def fetch_cluster_info!(config, pool: nil, **kwargs)
186185 node_info : node_info , pool : pool , with_replica : config . use_replica? , **kwargs )
187186 end
188187
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+
190191 cmd = command . first . to_s . downcase
191192 case cmd
192193 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
194195 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
200201 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 )
206207 when 'readonly' , 'readwrite' , 'shutdown'
207208 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 )
211212 when 'discard' , 'exec' , 'multi' , 'unwatch'
212213 raise ::RedisClient ::Cluster ::AmbiguousNodeError , cmd
213214 else
214215 node = assign_node ( *command )
215- try_send ( node , method , *command , **kwargs , &block )
216+ try_send ( node , method , *args , **kwargs , &block )
216217 end
217218 rescue RedisClient ::Cluster ::Node ::ReloadNeeded
218219 update_cluster_info!
219220 raise ::RedisClient ::Cluster ::NodeMightBeDown
220221 end
221222
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
224225 rescue RedisClient ::Cluster ::ErrorCollection => e
225226 raise if retry_count <= 0
226227 raise if e . errors . values . none? do |err |
@@ -232,64 +233,76 @@ def send_wait_command(method, *command, retry_count: 3, **kwargs, &block)
232233 retry
233234 end
234235
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+
236239 case command [ 1 ] . to_s . downcase
237240 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 )
240243 end
241244 end
242245
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+
244249 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 )
248253 end
249254 end
250255
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+
252259 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
254261 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 )
257264 end
258265 end
259266
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
261269 subcommand = command [ 1 ] . to_s . downcase
270+
262271 case subcommand
263272 when 'addslots' , 'delslots' , 'failover' , 'forget' , 'meet' , 'replicate' ,
264273 'reset' , 'set-config-epoch' , 'setslot'
265274 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
267276 when 'getkeysinslot'
268277 raise ArgumentError , command . join ( ' ' ) if command . size != 4
269278
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 )
272281 end
273282 end
274283
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+
276287 case command [ 1 ] . to_s . downcase
277288 when 'debug' , 'kill'
278- @node . call_all ( method , *command , **kwargs , &block ) . first
289+ @node . call_all ( method , *args , **kwargs , &block ) . first
279290 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 )
282293 end
283294 end
284295
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+
286299 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
288301 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 ] }
290303 . 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 )
293306 end
294307 end
295308
0 commit comments