@@ -72,45 +72,25 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
72
72
end
73
73
74
74
# @see https://redis.io/docs/reference/cluster-spec/#redirection-and-resharding Redirection and resharding
75
- def try_send ( node , method , command , args , retry_count : 3 , &block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
76
- if args . empty?
77
- # prevent memory allocation for variable-length args
78
- node . public_send ( method , command , &block )
79
- else
80
- node . public_send ( method , *args , command , &block )
81
- end
82
- rescue ::RedisClient ::CircuitBreaker ::OpenCircuitError
83
- raise
84
- rescue ::RedisClient ::CommandError => e
85
- if e . message . start_with? ( 'MOVED' )
86
- node = assign_redirection_node ( e . message )
87
- retry_count -= 1
88
- retry if retry_count >= 0
89
- elsif e . message . start_with? ( 'ASK' )
90
- node = assign_asking_node ( e . message )
91
- retry_count -= 1
92
- if retry_count >= 0
93
- # Don't actually prepend our next command with ASKING unless we're going to retry.
94
- node . call ( 'ASKING' )
95
- retry
75
+ def try_send ( node , method , command , args , retry_count : 3 , &block )
76
+ handle_redirection ( node , retry_count : retry_count ) do |on_node |
77
+ if args . empty?
78
+ # prevent memory allocation for variable-length args
79
+ on_node . public_send ( method , command , &block )
80
+ else
81
+ on_node . public_send ( method , *args , command , &block )
96
82
end
97
- elsif e . message . start_with? ( 'CLUSTERDOWN Hash slot not served' )
98
- update_cluster_info!
99
- retry_count -= 1
100
- retry if retry_count >= 0
101
83
end
102
- raise
103
- rescue ::RedisClient ::ConnectionError => e
104
- update_cluster_info!
105
-
106
- raise if retry_count <= 0
84
+ end
107
85
108
- retry_count -= 1
109
- retry
86
+ def try_delegate ( node , method , *args , retry_count : 3 , **kwargs , &block )
87
+ handle_redirection ( node , retry_count : retry_count ) do |on_node |
88
+ on_node . public_send ( method , *args , **kwargs , &block )
89
+ end
110
90
end
111
91
112
- def try_delegate ( node , method , * args , retry_count : 3 , ** kwargs , & block ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
113
- node . public_send ( method , * args , ** kwargs , & block )
92
+ def handle_redirection ( node , retry_count :) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
93
+ yield node
114
94
rescue ::RedisClient ::CircuitBreaker ::OpenCircuitError
115
95
raise
116
96
rescue ::RedisClient ::CommandError => e
0 commit comments