@@ -50,28 +50,31 @@ def get_block(inner_index)
50
50
end
51
51
52
52
::RedisClient ::ConnectionMixin . module_eval do
53
- def call_pipelined_aware_of_redirection ( commands , timeouts ) # rubocop:disable Metrics/AbcSize
53
+ def call_pipelined_aware_of_redirection ( commands , timeouts ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
54
54
size = commands . size
55
55
results = Array . new ( commands . size )
56
56
@pending_reads += size
57
57
write_multi ( commands )
58
58
59
59
redirection_indices = nil
60
+ exception = nil
60
61
size . times do |index |
61
62
timeout = timeouts && timeouts [ index ]
62
63
result = read ( timeout )
63
64
@pending_reads -= 1
64
- if result . is_a? ( CommandError )
65
+ if result . is_a? ( :: RedisClient :: Error )
65
66
result . _set_command ( commands [ index ] )
66
- if result . message . start_with? ( 'MOVED' , 'ASK' )
67
+ if result . is_a? ( :: RedisClient :: CommandError ) && result . message . start_with? ( 'MOVED' , 'ASK' )
67
68
redirection_indices ||= [ ]
68
69
redirection_indices << index
70
+ else
71
+ exception ||= result
69
72
end
70
73
end
71
-
72
74
results [ index ] = result
73
75
end
74
76
77
+ raise exception if exception
75
78
return results if redirection_indices . nil?
76
79
77
80
err = ::RedisClient ::Cluster ::Pipeline ::RedirectionNeeded . new
@@ -217,21 +220,15 @@ def handle_redirection(err, pipeline, inner_index)
217
220
218
221
if err . message . start_with? ( 'MOVED' )
219
222
node = @router . assign_redirection_node ( err . message )
220
- try_redirection ( node , pipeline , inner_index )
223
+ redirect_command ( node , pipeline , inner_index )
221
224
elsif err . message . start_with? ( 'ASK' )
222
225
node = @router . assign_asking_node ( err . message )
223
- try_asking ( node ) ? try_redirection ( node , pipeline , inner_index ) : err
226
+ try_asking ( node ) ? redirect_command ( node , pipeline , inner_index ) : err
224
227
else
225
228
err
226
229
end
227
230
end
228
231
229
- def try_redirection ( node , pipeline , inner_index )
230
- redirect_command ( node , pipeline , inner_index )
231
- rescue StandardError => e
232
- e
233
- end
234
-
235
232
def redirect_command ( node , pipeline , inner_index )
236
233
method = pipeline . get_callee_method ( inner_index )
237
234
command = pipeline . get_command ( inner_index )
0 commit comments