@@ -20,6 +20,15 @@ class Router
20
20
DEDICATED_ACTIONS = lambda do # rubocop:disable Metrics/BlockLength
21
21
action = Struct . new ( 'RedisCommandRoutingAction' , :method_name , :reply_transformer , keyword_init : true )
22
22
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
23
32
multiple_key_action = action . new ( method_name : :send_multiple_keys_command )
24
33
all_node_first_action = action . new ( method_name : :send_command_to_all_nodes , reply_transformer : pick_first )
25
34
primary_first_action = action . new ( method_name : :send_command_to_primaries , reply_transformer : pick_first )
@@ -28,10 +37,10 @@ class Router
28
37
{
29
38
'ping' => action . new ( method_name : :send_ping_command , reply_transformer : pick_first ) ,
30
39
'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 ) ,
33
42
'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 ) ,
35
44
'role' => action . new ( method_name : :send_command_to_all_nodes ) ,
36
45
'config' => action . new ( method_name : :send_config_command ) ,
37
46
'client' => action . new ( method_name : :send_client_command ) ,
@@ -59,8 +68,8 @@ class Router
59
68
'multi' => keyless_action ,
60
69
'unwatch' => keyless_action
61
70
} . 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
64
73
end
65
74
end . call . freeze
66
75
0 commit comments