@@ -13,11 +13,18 @@ class Cluster
1313 class Node
1414 include Enumerable
1515
16+ # It affects to strike a balance between load and stability in initialization or changed states.
17+ MAX_STARTUP_SAMPLE = Integer ( ENV . fetch ( 'REDIS_CLIENT_MAX_STARTUP_SAMPLE' , 3 ) )
18+
19+ # It's used with slow queries of fetching meta data like CLUSTER NODES, COMMAND and so on.
20+ SLOW_COMMAND_TIMEOUT = Float ( ENV . fetch ( 'REDIS_CLIENT_SLOW_COMMAND_TIMEOUT' , -1 ) )
21+
22+ # less memory consumption, but slow
23+ USE_CHAR_ARRAY_SLOT = Integer ( ENV . fetch ( 'REDIS_CLIENT_USE_CHAR_ARRAY_SLOT' , 1 ) ) == 1
24+
1625 SLOT_SIZE = 16_384
1726 MIN_SLOT = 0
1827 MAX_SLOT = SLOT_SIZE - 1
19- MAX_STARTUP_SAMPLE = Integer ( ENV . fetch ( 'REDIS_CLIENT_MAX_STARTUP_SAMPLE' , 3 ) )
20- USE_CHAR_ARRAY_SLOT = Integer ( ENV . fetch ( 'REDIS_CLIENT_USE_CHAR_ARRAY_SLOT' , 1 ) ) == 1 # less memory consumption, but slow
2128 IGNORE_GENERIC_CONFIG_KEYS = %i[ url host port path ] . freeze
2229 DEAD_FLAGS = %w[ fail? fail handshake noaddr noflags ] . freeze
2330 ROLE_FLAGS = %w[ master slave ] . freeze
@@ -99,7 +106,10 @@ def load_info(options, concurrent_worker, **kwargs) # rubocop:disable Metrics/Ab
99106
100107 startup_nodes . each_with_index do |raw_client , i |
101108 work_group . push ( i , raw_client ) do |client |
109+ regular_timeout = client . read_timeout
110+ client . read_timeout = SLOW_COMMAND_TIMEOUT > 0.0 ? SLOW_COMMAND_TIMEOUT : regular_timeout
102111 reply = client . call ( 'CLUSTER' , 'NODES' )
112+ client . read_timeout = regular_timeout
103113 parse_cluster_node_reply ( reply )
104114 rescue StandardError => e
105115 e
@@ -209,10 +219,6 @@ def each(&block)
209219 @topology . clients . each_value ( &block )
210220 end
211221
212- def shuffled_nodes
213- @topology . clients . values . shuffle
214- end
215-
216222 def sample
217223 @topology . clients . values . sample
218224 end
@@ -252,6 +258,10 @@ def clients_for_scanning(seed: nil)
252258 @topology . clients_for_scanning ( seed : seed ) . values . sort_by { |c | "#{ c . config . host } -#{ c . config . port } " }
253259 end
254260
261+ def replica_clients
262+ @topology . replica_clients . values
263+ end
264+
255265 def find_node_key_of_primary ( slot )
256266 return if slot . nil?
257267
0 commit comments