@@ -20,6 +20,15 @@ class Router
2020 DEDICATED_ACTIONS = lambda do # rubocop:disable Metrics/BlockLength
2121 action = Struct . new ( 'RedisCommandRoutingAction' , :method_name , :reply_transformer , keyword_init : true )
2222 pick_first = -> ( reply ) { reply . first } # rubocop:disable Style/SymbolProc
23+ flatten_strings = -> ( reply ) { reply . flatten . sort_by ( &:to_s ) }
24+ sum_num = -> ( reply ) { reply . select { |e | e . is_a? ( Integer ) } . sum }
25+ sort_numbers = -> ( reply ) { reply . sort_by ( &:to_i ) }
26+ if Object . const_defined? ( :Ractor , false ) && Ractor . respond_to? ( :make_shareable )
27+ Ractor . make_shareable ( pick_first )
28+ Ractor . make_shareable ( flatten_strings )
29+ Ractor . make_shareable ( sum_num )
30+ Ractor . make_shareable ( sort_numbers )
31+ end
2332 multiple_key_action = action . new ( method_name : :send_multiple_keys_command )
2433 all_node_first_action = action . new ( method_name : :send_command_to_all_nodes , reply_transformer : pick_first )
2534 primary_first_action = action . new ( method_name : :send_command_to_primaries , reply_transformer : pick_first )
@@ -28,10 +37,10 @@ class Router
2837 {
2938 'ping' => action . new ( method_name : :send_ping_command , reply_transformer : pick_first ) ,
3039 'wait' => action . new ( method_name : :send_wait_command ) ,
31- 'keys' => action . new ( method_name : :send_command_to_replicas , reply_transformer : -> ( reply ) { reply . flatten . sort_by ( & :to_s ) } ) ,
32- 'dbsize' => action . new ( method_name : :send_command_to_replicas , reply_transformer : -> ( reply ) { reply . select { | e | e . is_a? ( Integer ) } . sum } ) ,
40+ 'keys' => action . new ( method_name : :send_command_to_replicas , reply_transformer : flatten_strings ) ,
41+ 'dbsize' => action . new ( method_name : :send_command_to_replicas , reply_transformer : sum_num ) ,
3342 'scan' => action . new ( method_name : :send_scan_command ) ,
34- 'lastsave' => action . new ( method_name : :send_command_to_all_nodes , reply_transformer : -> ( reply ) { reply . sort_by ( & :to_i ) } ) ,
43+ 'lastsave' => action . new ( method_name : :send_command_to_all_nodes , reply_transformer : sort_numbers ) ,
3544 'role' => action . new ( method_name : :send_command_to_all_nodes ) ,
3645 'config' => action . new ( method_name : :send_config_command ) ,
3746 'client' => action . new ( method_name : :send_client_command ) ,
@@ -59,8 +68,8 @@ class Router
5968 'multi' => keyless_action ,
6069 'unwatch' => keyless_action
6170 } . each_with_object ( { } ) do |( k , v ) , acc |
62- acc [ k ] = v
63- acc [ k . upcase ] = v
71+ acc [ k ] = v . freeze
72+ acc [ k . upcase ] = v . freeze
6473 end
6574 end . call . freeze
6675
0 commit comments