@@ -17,9 +17,19 @@ class Cluster
1717 class Router
1818 ZERO_CURSOR_FOR_SCAN = '0'
1919 TSF = -> ( f , x ) { f . nil? ? x : f . call ( x ) } . curry
20+ Ractor . make_shareable ( TSF ) if Object . const_defined? ( :Ractor , false ) && Ractor . respond_to? ( :make_shareable )
2021 DEDICATED_ACTIONS = lambda do # rubocop:disable Metrics/BlockLength
2122 action = Struct . new ( 'RedisCommandRoutingAction' , :method_name , :reply_transformer , keyword_init : true )
2223 pick_first = -> ( reply ) { reply . first } # rubocop:disable Style/SymbolProc
24+ flatten_strings = -> ( reply ) { reply . flatten . sort_by ( &:to_s ) }
25+ sum_num = -> ( reply ) { reply . select { |e | e . is_a? ( Integer ) } . sum }
26+ sort_numbers = -> ( reply ) { reply . sort_by ( &:to_i ) }
27+ if Object . const_defined? ( :Ractor , false ) && Ractor . respond_to? ( :make_shareable )
28+ Ractor . make_shareable ( pick_first )
29+ Ractor . make_shareable ( flatten_strings )
30+ Ractor . make_shareable ( sum_num )
31+ Ractor . make_shareable ( sort_numbers )
32+ end
2333 multiple_key_action = action . new ( method_name : :send_multiple_keys_command )
2434 all_node_first_action = action . new ( method_name : :send_command_to_all_nodes , reply_transformer : pick_first )
2535 primary_first_action = action . new ( method_name : :send_command_to_primaries , reply_transformer : pick_first )
@@ -28,10 +38,10 @@ class Router
2838 {
2939 'ping' => action . new ( method_name : :send_ping_command , reply_transformer : pick_first ) ,
3040 '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 } ) ,
41+ 'keys' => action . new ( method_name : :send_command_to_replicas , reply_transformer : flatten_strings ) ,
42+ 'dbsize' => action . new ( method_name : :send_command_to_replicas , reply_transformer : sum_num ) ,
3343 '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 ) } ) ,
44+ 'lastsave' => action . new ( method_name : :send_command_to_all_nodes , reply_transformer : sort_numbers ) ,
3545 'role' => action . new ( method_name : :send_command_to_all_nodes ) ,
3646 'config' => action . new ( method_name : :send_config_command ) ,
3747 'client' => action . new ( method_name : :send_client_command ) ,
@@ -59,8 +69,8 @@ class Router
5969 'multi' => keyless_action ,
6070 'unwatch' => keyless_action
6171 } . each_with_object ( { } ) do |( k , v ) , acc |
62- acc [ k ] = v
63- acc [ k . upcase ] = v
72+ acc [ k ] = v . freeze
73+ acc [ k . upcase ] = v . freeze
6474 end
6575 end . call . freeze
6676
0 commit comments