@@ -24,8 +24,8 @@ class Router
2424
2525 Action = Struct . new (
2626 'RedisCommandRoutingAction' ,
27- :action_method_name ,
28- :after_action_proc ,
27+ :method_name ,
28+ :reply_transformer ,
2929 keyword_init : true
3030 )
3131
@@ -48,10 +48,10 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
4848 return assign_node_and_send_command ( method , command , args , &block ) unless @dedicated_actions . key? ( command . first )
4949
5050 action = @dedicated_actions [ command . first ]
51- return send ( action . action_method_name , method , command , args , &block ) if action . after_action_proc . nil?
51+ return send ( action . method_name , method , command , args , &block ) if action . reply_transformer . nil?
5252
53- reply = send ( action . action_method_name , method , command , args )
54- action . after_action_proc . call ( reply ) . then ( &TSF . call ( block ) )
53+ reply = send ( action . method_name , method , command , args )
54+ action . reply_transformer . call ( reply ) . then ( &TSF . call ( block ) )
5555 rescue ::RedisClient ::CircuitBreaker ::OpenCircuitError
5656 raise
5757 rescue ::RedisClient ::Cluster ::Node ::ReloadNeeded
@@ -259,26 +259,26 @@ def close
259259
260260 def build_dedicated_actions # rubocop:disable Metrics/AbcSize
261261 pick_first = -> ( reply ) { reply . first } # rubocop:disable Style/SymbolProc
262- multiple_key_action = Action . new ( action_method_name : :send_multiple_keys_command )
263- all_node_first_action = Action . new ( action_method_name : :send_command_to_all_nodes , after_action_proc : pick_first )
264- primary_first_action = Action . new ( action_method_name : :send_command_to_primaries , after_action_proc : pick_first )
265- not_supported_action = Action . new ( action_method_name : :fail_not_supported_command )
266- keyless_action = Action . new ( action_method_name : :fail_keyless_command )
262+ multiple_key_action = Action . new ( method_name : :send_multiple_keys_command )
263+ all_node_first_action = Action . new ( method_name : :send_command_to_all_nodes , reply_transformer : pick_first )
264+ primary_first_action = Action . new ( method_name : :send_command_to_primaries , reply_transformer : pick_first )
265+ not_supported_action = Action . new ( method_name : :fail_not_supported_command )
266+ keyless_action = Action . new ( method_name : :fail_keyless_command )
267267 actions = {
268- 'ping' => Action . new ( action_method_name : :send_ping_command , after_action_proc : pick_first ) ,
269- 'wait' => Action . new ( action_method_name : :send_wait_command ) ,
270- 'keys' => Action . new ( action_method_name : :send_command_to_replicas , after_action_proc : -> ( reply ) { reply . flatten . sort_by ( &:to_s ) } ) ,
271- 'dbsize' => Action . new ( action_method_name : :send_command_to_replicas , after_action_proc : -> ( reply ) { reply . select { |e | e . is_a? ( Integer ) } . sum } ) ,
272- 'scan' => Action . new ( action_method_name : :send_scan_command ) ,
273- 'lastsave' => Action . new ( action_method_name : :send_command_to_all_nodes , after_action_proc : -> ( reply ) { reply . sort_by ( &:to_i ) } ) ,
274- 'role' => Action . new ( action_method_name : :send_command_to_all_nodes ) ,
275- 'config' => Action . new ( action_method_name : :send_config_command ) ,
276- 'client' => Action . new ( action_method_name : :send_client_command ) ,
277- 'cluster' => Action . new ( action_method_name : :send_cluster_command ) ,
278- 'memory' => Action . new ( action_method_name : :send_memory_command ) ,
279- 'script' => Action . new ( action_method_name : :send_script_command ) ,
280- 'pubsub' => Action . new ( action_method_name : :send_pubsub_command ) ,
281- 'watch' => Action . new ( action_method_name : :send_watch_command ) ,
268+ 'ping' => Action . new ( method_name : :send_ping_command , reply_transformer : pick_first ) ,
269+ 'wait' => Action . new ( method_name : :send_wait_command ) ,
270+ 'keys' => Action . new ( method_name : :send_command_to_replicas , reply_transformer : -> ( reply ) { reply . flatten . sort_by ( &:to_s ) } ) ,
271+ 'dbsize' => Action . new ( method_name : :send_command_to_replicas , reply_transformer : -> ( reply ) { reply . select { |e | e . is_a? ( Integer ) } . sum } ) ,
272+ 'scan' => Action . new ( method_name : :send_scan_command ) ,
273+ 'lastsave' => Action . new ( method_name : :send_command_to_all_nodes , reply_transformer : -> ( reply ) { reply . sort_by ( &:to_i ) } ) ,
274+ 'role' => Action . new ( method_name : :send_command_to_all_nodes ) ,
275+ 'config' => Action . new ( method_name : :send_config_command ) ,
276+ 'client' => Action . new ( method_name : :send_client_command ) ,
277+ 'cluster' => Action . new ( method_name : :send_cluster_command ) ,
278+ 'memory' => Action . new ( method_name : :send_memory_command ) ,
279+ 'script' => Action . new ( method_name : :send_script_command ) ,
280+ 'pubsub' => Action . new ( method_name : :send_pubsub_command ) ,
281+ 'watch' => Action . new ( method_name : :send_watch_command ) ,
282282 'mget' => multiple_key_action ,
283283 'mset' => multiple_key_action ,
284284 'del' => multiple_key_action ,
0 commit comments