@@ -83,60 +83,62 @@ def try_send(node, method, command, args, retry_count: 3, &block) # rubocop:disa
83
83
rescue ::RedisClient ::CircuitBreaker ::OpenCircuitError
84
84
raise
85
85
rescue ::RedisClient ::CommandError => e
86
- raise if retry_count <= 0
87
-
88
86
if e . message . start_with? ( 'MOVED' )
89
87
node = assign_redirection_node ( e . message )
90
88
retry_count -= 1
91
- retry
89
+ retry if retry_count >= 0
92
90
elsif e . message . start_with? ( 'ASK' )
93
91
node = assign_asking_node ( e . message )
94
- node . call ( 'ASKING' )
95
92
retry_count -= 1
96
- retry
93
+ if retry_count >= 0
94
+ # Don't actually prepend our next command with ASKING unless we're going to retry.
95
+ node . call ( 'ASKING' )
96
+ retry
97
+ end
97
98
elsif e . message . start_with? ( 'CLUSTERDOWN Hash slot not served' )
98
99
update_cluster_info!
99
100
retry_count -= 1
100
- retry
101
- else
102
- raise
101
+ retry if retry_count >= 0
103
102
end
103
+ raise
104
104
rescue ::RedisClient ::ConnectionError => e
105
105
raise if METHODS_FOR_BLOCKING_CMD . include? ( method ) && e . is_a? ( RedisClient ::ReadTimeoutError )
106
- raise if retry_count <= 0
107
106
108
107
update_cluster_info!
108
+
109
+ raise if retry_count <= 0
110
+
109
111
retry_count -= 1
110
112
retry
111
113
end
112
114
113
- def try_delegate ( node , method , *args , retry_count : 3 , **kwargs , &block ) # rubocop:disable Metrics/AbcSize
115
+ def try_delegate ( node , method , *args , retry_count : 3 , **kwargs , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
114
116
node . public_send ( method , *args , **kwargs , &block )
115
117
rescue ::RedisClient ::CircuitBreaker ::OpenCircuitError
116
118
raise
117
119
rescue ::RedisClient ::CommandError => e
118
- raise if retry_count <= 0
119
-
120
120
if e . message . start_with? ( 'MOVED' )
121
121
node = assign_redirection_node ( e . message )
122
122
retry_count -= 1
123
- retry
123
+ retry if retry_count >= 0
124
124
elsif e . message . start_with? ( 'ASK' )
125
125
node = assign_asking_node ( e . message )
126
- node . call ( 'ASKING' )
127
126
retry_count -= 1
128
- retry
127
+ if retry_count >= 0
128
+ node . call ( 'ASKING' )
129
+ retry
130
+ end
129
131
elsif e . message . start_with? ( 'CLUSTERDOWN Hash slot not served' )
130
132
update_cluster_info!
131
133
retry_count -= 1
132
- retry
133
- else
134
- raise
134
+ retry if retry_count >= 0
135
135
end
136
+ raise
136
137
rescue ::RedisClient ::ConnectionError
138
+ update_cluster_info!
139
+
137
140
raise if retry_count <= 0
138
141
139
- update_cluster_info!
140
142
retry_count -= 1
141
143
retry
142
144
end
0 commit comments