redis-cluster-client 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/pub_sub.rb +33 -20
- data/lib/redis_client/cluster/router.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce265da4f3a871e187b651c27ce9ee1d9a9321e346c2b1c3d1eba6f40139192
|
4
|
+
data.tar.gz: 95252d4d8b20e77a3bcc91035208c3d9baafbf2ad31d60adaa4376b38c75c2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b7b9f733569fe7ba66dc4d49241ac827e6c3e23ea74fa9a04efbb985b601ca575302b8316e891160896d880cc74a2bdb3b88533478cbdab8e1e90b6d2d8926
|
7
|
+
data.tar.gz: a7982da3ad7a8a373f1ce9993262a279e50889be71bdc5913806da006a9252b65d3574bf816bc2ddb98f0034b6195890c23486eb2155d2ca8a6785753c3f69f1
|
@@ -89,12 +89,13 @@ class RedisClient
|
|
89
89
|
|
90
90
|
case event = @queue.pop(true)
|
91
91
|
when ::RedisClient::CommandError
|
92
|
-
|
93
|
-
@router.renew_cluster_state
|
94
|
-
break start_over
|
95
|
-
end
|
92
|
+
raise event unless event.message.start_with?('MOVED', 'CLUSTERDOWN Hash slot not served')
|
96
93
|
|
97
|
-
|
94
|
+
@router.renew_cluster_state
|
95
|
+
break start_over
|
96
|
+
when ::RedisClient::ConnectionError
|
97
|
+
@router.renew_cluster_state
|
98
|
+
break start_over
|
98
99
|
when StandardError then raise event
|
99
100
|
when Array then break event
|
100
101
|
end
|
@@ -114,25 +115,20 @@ class RedisClient
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
|
-
def call_to_single_state(command
|
118
|
+
def call_to_single_state(command)
|
118
119
|
node_key = @router.find_node_key(command)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@router.renew_cluster_state
|
125
|
-
retry_count -= 1
|
126
|
-
retry_count >= 0 ? retry : raise
|
120
|
+
|
121
|
+
handle_connection_error(node_key) do
|
122
|
+
@state_dict[node_key] ||= State.new(@router.find_node(node_key).pubsub, @queue)
|
123
|
+
@state_dict[node_key].call(command)
|
124
|
+
end
|
127
125
|
end
|
128
126
|
|
129
127
|
def call_to_all_states(command)
|
130
128
|
@state_dict.each do |node_key, state|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
@state_dict.delete(node_key)
|
135
|
-
@router.renew_cluster_state
|
129
|
+
handle_connection_error(node_key, ignore: true) do
|
130
|
+
state.call(command)
|
131
|
+
end
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
@@ -152,10 +148,27 @@ class RedisClient
|
|
152
148
|
timeout.nil? || timeout < 0 ? 0 : timeout * 1_000_000
|
153
149
|
end
|
154
150
|
|
151
|
+
def handle_connection_error(node_key, ignore: false)
|
152
|
+
yield
|
153
|
+
rescue ::RedisClient::ConnectionError
|
154
|
+
@state_dict[node_key].close
|
155
|
+
@state_dict.delete(node_key)
|
156
|
+
@router.renew_cluster_state
|
157
|
+
raise unless ignore
|
158
|
+
end
|
159
|
+
|
155
160
|
def start_over
|
156
161
|
@state_dict.each_value(&:close)
|
157
162
|
@state_dict.clear
|
158
|
-
@commands.each
|
163
|
+
@commands.each do |command|
|
164
|
+
loop do
|
165
|
+
_call(command)
|
166
|
+
break
|
167
|
+
rescue ::RedisClient::ConnectionError
|
168
|
+
sleep 1.0
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
159
172
|
nil
|
160
173
|
end
|
161
174
|
end
|
@@ -175,7 +175,12 @@ class RedisClient
|
|
175
175
|
def find_node_key_by_key(key, seed: nil, primary: false)
|
176
176
|
if key && !key.empty?
|
177
177
|
slot = ::RedisClient::Cluster::KeySlotConverter.convert(key)
|
178
|
-
primary ? @node.find_node_key_of_primary(slot) : @node.find_node_key_of_replica(slot)
|
178
|
+
node_key = primary ? @node.find_node_key_of_primary(slot) : @node.find_node_key_of_replica(slot)
|
179
|
+
if node_key.nil?
|
180
|
+
renew_cluster_state
|
181
|
+
raise ::RedisClient::Cluster::NodeMightBeDown
|
182
|
+
end
|
183
|
+
node_key
|
179
184
|
else
|
180
185
|
primary ? @node.any_primary_node_key(seed: seed) : @node.any_replica_node_key(seed: seed)
|
181
186
|
end
|