@@ -21,17 +21,20 @@ class Router
21
21
22
22
private_constant :ZERO_CURSOR_FOR_SCAN , :TSF
23
23
24
+ attr_reader :config
25
+
24
26
def initialize ( config , concurrent_worker , pool : nil , **kwargs )
25
- @config = config . dup
26
- @original_config = config . dup if config . connect_with_original_config
27
- @connect_with_original_config = config . connect_with_original_config
27
+ @config = config
28
28
@concurrent_worker = concurrent_worker
29
29
@pool = pool
30
30
@client_kwargs = kwargs
31
31
@node = ::RedisClient ::Cluster ::Node . new ( concurrent_worker , config : config , pool : pool , **kwargs )
32
32
@node . reload!
33
33
@command = ::RedisClient ::Cluster ::Command . load ( @node . replica_clients . shuffle , slow_command_timeout : config . slow_command_timeout )
34
34
@command_builder = @config . command_builder
35
+ rescue ::RedisClient ::Cluster ::InitialSetupError => e
36
+ e . with_config ( config )
37
+ raise
35
38
end
36
39
37
40
def send_command ( method , command , *args , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -58,9 +61,9 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
58
61
when 'flushall' , 'flushdb'
59
62
@node . call_primaries ( method , command , args ) . first . then ( &TSF . call ( block ) )
60
63
when 'readonly' , 'readwrite' , 'shutdown'
61
- raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported , cmd
64
+ raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported . from_command ( cmd ) . with_config ( @config )
62
65
when 'discard' , 'exec' , 'multi' , 'unwatch'
63
- raise ::RedisClient ::Cluster ::AmbiguousNodeError , cmd
66
+ raise ::RedisClient ::Cluster ::AmbiguousNodeError . from_command ( cmd ) . with_config ( @config )
64
67
else
65
68
node = assign_node ( command )
66
69
try_send ( node , method , command , args , &block )
@@ -69,14 +72,15 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
69
72
raise
70
73
rescue ::RedisClient ::Cluster ::Node ::ReloadNeeded
71
74
renew_cluster_state
72
- raise ::RedisClient ::Cluster ::NodeMightBeDown
75
+ raise ::RedisClient ::Cluster ::NodeMightBeDown . new . with_config ( @config )
73
76
rescue ::RedisClient ::ConnectionError
74
77
renew_cluster_state
75
78
raise
76
79
rescue ::RedisClient ::CommandError => e
77
80
renew_cluster_state if e . message . start_with? ( 'CLUSTERDOWN' )
78
81
raise
79
82
rescue ::RedisClient ::Cluster ::ErrorCollection => e
83
+ e . with_config ( @config )
80
84
raise if e . errors . any? ( ::RedisClient ::CircuitBreaker ::OpenCircuitError )
81
85
82
86
renew_cluster_state if e . errors . values . any? do |err |
@@ -189,7 +193,7 @@ def find_node_key_by_key(key, seed: nil, primary: false)
189
193
node_key = primary ? @node . find_node_key_of_primary ( slot ) : @node . find_node_key_of_replica ( slot )
190
194
if node_key . nil?
191
195
renew_cluster_state
192
- raise ::RedisClient ::Cluster ::NodeMightBeDown
196
+ raise ::RedisClient ::Cluster ::NodeMightBeDown . new . with_config ( @config )
193
197
end
194
198
node_key
195
199
else
@@ -303,7 +307,7 @@ def send_cluster_command(method, command, args, &block) # rubocop:disable Metric
303
307
case subcommand = ::RedisClient ::Cluster ::NormalizedCmdName . instance . get_by_subcommand ( command )
304
308
when 'addslots' , 'delslots' , 'failover' , 'forget' , 'meet' , 'replicate' ,
305
309
'reset' , 'set-config-epoch' , 'setslot'
306
- raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported , [ 'cluster' , subcommand ]
310
+ raise ::RedisClient ::Cluster ::OrchestrationCommandNotSupported . from_command ( [ 'cluster' , subcommand ] ) . with_config ( @config )
307
311
when 'saveconfig' then @node . call_all ( method , command , args ) . first . then ( &TSF . call ( block ) )
308
312
when 'getkeysinslot'
309
313
raise ArgumentError , command . join ( ' ' ) if command . size != 4
@@ -347,7 +351,10 @@ def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics
347
351
end
348
352
349
353
def send_watch_command ( command )
350
- raise ::RedisClient ::Cluster ::Transaction ::ConsistencyError , 'A block required. And you need to use the block argument as a client for the transaction.' unless block_given?
354
+ unless block_given?
355
+ msg = 'A block required. And you need to use the block argument as a client for the transaction.'
356
+ raise ::RedisClient ::Cluster ::Transaction ::ConsistencyError . new ( msg ) . with_config ( @config )
357
+ end
351
358
352
359
::RedisClient ::Cluster ::OptimisticLocking . new ( self ) . watch ( command [ 1 ..] ) do |c , slot , asking |
353
360
transaction = ::RedisClient ::Cluster ::Transaction . new (
@@ -401,7 +408,7 @@ def send_multiple_keys_command(cmd, method, command, args, &block) # rubocop:dis
401
408
def handle_node_reload_error ( retry_count : 1 )
402
409
yield
403
410
rescue ::RedisClient ::Cluster ::Node ::ReloadNeeded
404
- raise ::RedisClient ::Cluster ::NodeMightBeDown if retry_count <= 0
411
+ raise ::RedisClient ::Cluster ::NodeMightBeDown . new . with_config ( @config ) if retry_count <= 0
405
412
406
413
retry_count -= 1
407
414
renew_cluster_state
0 commit comments