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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd66efdf343224572aeffdbfdd4cb96c8189bd45183c0a3934e6dd1964a35655
4
- data.tar.gz: 66805c538066aabab413b767f0b9e8756c1eff8920f410a665939f18d69c0621
3
+ metadata.gz: 9ce265da4f3a871e187b651c27ce9ee1d9a9321e346c2b1c3d1eba6f40139192
4
+ data.tar.gz: 95252d4d8b20e77a3bcc91035208c3d9baafbf2ad31d60adaa4376b38c75c2fa
5
5
  SHA512:
6
- metadata.gz: d325c2955718451c15084b58b0231d521065ebe1b8b549f79106f26132b50eb77ac90e6b0dcfb11868eb80b2d37a742f741b21d963c6ff92faacf4d88bc64830
7
- data.tar.gz: 7e6c92442c2852b0533c19b4e60ff8e8e6532d55cbeebc9424e1b62081c6eb21af6a5717ae04fbb683083c271d3008934d0e17becc4b7abf232c005304c2b713
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
- if event.message.start_with?('MOVED', 'CLUSTERDOWN Hash slot not served')
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
- raise event
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, retry_count: 1)
118
+ def call_to_single_state(command)
118
119
  node_key = @router.find_node_key(command)
119
- @state_dict[node_key] ||= State.new(@router.find_node(node_key).pubsub, @queue)
120
- @state_dict[node_key].call(command)
121
- rescue ::RedisClient::ConnectionError
122
- @state_dict[node_key].close
123
- @state_dict.delete(node_key)
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
- state.call(command)
132
- rescue ::RedisClient::ConnectionError
133
- @state_dict[node_key].close
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 { |command| _call(command) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga