redis-cluster-client 0.0.6 → 0.0.7

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: fde84481c2ca9680670f252a002391a34ae793148a21a8e02086d199412a53ab
4
- data.tar.gz: 5af188432f9ae5e76c13d0dd174c25cde4b98d1de49efeb97e2a809bd111a9a6
3
+ metadata.gz: aff938c0517542c32f98206c28f1f605a52751e2e2e9a1bd10f5576285f568ee
4
+ data.tar.gz: 8a3d45fba93334959b1ee67504d2703bb116a8133ef8dac2aa8f314fdb74b268
5
5
  SHA512:
6
- metadata.gz: f26dc7bb447ee70742efc90344758ad3058cd0d1506ad8576637b7e9ad296a806d7e15e3b824cead0fb2313140dea00f6f579a15803399c16257ac347c45085f
7
- data.tar.gz: 06f43e223a53d9ada0803f7292bc1ca58505fb3c341fd7643eb6cf0eff73bebe4ecd2022b0a1b59af81dda879a9d8a9b078107181ff45037773382dada321597
6
+ metadata.gz: 63dec0155a50a0dbb7a17763c43291d371abe4e3df407340ba8edf125cf2c2bb338f607026a1d004dca489761cb2e6b5450e68a468f18799e5c3443b52a21be7
7
+ data.tar.gz: 4de6c4688ca120d7f4b636bd884195b3cddc3bf8d217ea662a1f382ced46de2c9e24b0e967a801d175f0572a083b9e5ea835d54797422cf60ce799cda3002f74
@@ -29,7 +29,7 @@ class RedisClient
29
29
  end
30
30
 
31
31
  # Raised when error occurs on any node of cluster.
32
- class CommandErrorCollection < ::RedisClient::Error
32
+ class ErrorCollection < ::RedisClient::Error
33
33
  attr_reader :errors
34
34
 
35
35
  def initialize(errors)
@@ -118,7 +118,7 @@ class RedisClient
118
118
  try_map { |_, client| client.send(method, *command, **kwargs, &block) }.values
119
119
  end
120
120
 
121
- def call_primary(method, *command, **kwargs, &block)
121
+ def call_primaries(method, *command, **kwargs, &block)
122
122
  try_map do |node_key, client|
123
123
  next if replica?(node_key)
124
124
 
@@ -126,8 +126,8 @@ class RedisClient
126
126
  end.values
127
127
  end
128
128
 
129
- def call_replica(method, *command, **kwargs, &block)
130
- return call_primary(method, *command, **kwargs, &block) if replica_disabled?
129
+ def call_replicas(method, *command, **kwargs, &block)
130
+ return call_primaries(method, *command, **kwargs, &block) if replica_disabled?
131
131
 
132
132
  replica_node_keys = @replications.values.map(&:sample)
133
133
  try_map do |node_key, client|
@@ -228,14 +228,14 @@ class RedisClient
228
228
  end
229
229
 
230
230
  def try_map # rubocop:disable Metrics/MethodLength
231
- errors = {}
232
231
  results = {}
232
+ errors = {}
233
233
  threads = @clients.map do |k, v|
234
234
  Thread.new(k, v) do |node_key, client|
235
235
  Thread.pass
236
236
  reply = yield(node_key, client)
237
237
  results[node_key] = reply unless reply.nil?
238
- rescue ::RedisClient::CommandError => e
238
+ rescue StandardError => e
239
239
  errors[node_key] = e
240
240
  end
241
241
  end
@@ -243,7 +243,7 @@ class RedisClient
243
243
  threads.each(&:join)
244
244
  return results if errors.empty?
245
245
 
246
- raise ::RedisClient::Cluster::CommandErrorCollection, errors
246
+ raise ::RedisClient::Cluster::ErrorCollection, errors
247
247
  end
248
248
  end
249
249
  end
@@ -40,9 +40,10 @@ class RedisClient
40
40
  @size.zero?
41
41
  end
42
42
 
43
- # TODO: https://github.com/redis-rb/redis-cluster-client/issues/37
44
- def execute # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
43
+ # TODO: https://github.com/redis-rb/redis-cluster-client/issues/37 handle redirections
44
+ def execute # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
45
45
  all_replies = Array.new(@size)
46
+ errors = {}
46
47
  threads = @grouped.map do |k, v|
47
48
  Thread.new(@client, k, v) do |client, node_key, rows|
48
49
  Thread.pass
@@ -60,11 +61,15 @@ class RedisClient
60
61
  raise ReplySizeError, "commands: #{rows.size}, replies: #{replies.size}" if rows.size != replies.size
61
62
 
62
63
  rows.each_with_index { |row, idx| all_replies[row.first] = replies[idx] }
64
+ rescue StandardError => e
65
+ errors[node_key] = e
63
66
  end
64
67
  end
65
68
 
66
69
  threads.each(&:join)
67
- all_replies
70
+ return all_replies if errors.empty?
71
+
72
+ raise ::RedisClient::Cluster::ErrorCollection, errors
68
73
  end
69
74
  end
70
75
 
@@ -185,10 +190,10 @@ class RedisClient
185
190
  when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save', 'ping'
186
191
  @node.call_all(method, *command, **kwargs, &block).first
187
192
  when 'flushall', 'flushdb'
188
- @node.call_primary(method, *command, **kwargs, &block).first
193
+ @node.call_primaries(method, *command, **kwargs, &block).first
189
194
  when 'wait' then send_wait_command(method, *command, **kwargs, &block)
190
- when 'keys' then @node.call_replica(method, *command, **kwargs, &block).flatten.sort
191
- when 'dbsize' then @node.call_replica(method, *command, **kwargs, &block).sum
195
+ when 'keys' then @node.call_replicas(method, *command, **kwargs, &block).flatten.sort
196
+ when 'dbsize' then @node.call_replicas(method, *command, **kwargs, &block).sum
192
197
  when 'scan' then _scan(*command, **kwargs)
193
198
  when 'lastsave' then @node.call_all(method, *command, **kwargs, &block).sort
194
199
  when 'role' then @node.call_all(method, *command, **kwargs, &block)
@@ -206,14 +211,14 @@ class RedisClient
206
211
  node = assign_node(*command)
207
212
  try_send(node, method, *command, **kwargs, &block)
208
213
  end
209
- rescue RedisClient::Cluster::CommandErrorCollection => e
214
+ rescue RedisClient::Cluster::ErrorCollection => e
210
215
  update_cluster_info! if e.errors.values.map(&:class).any?(::RedisClient::ConnectionError)
211
216
  raise
212
217
  end
213
218
 
214
219
  def send_wait_command(method, *command, retry_count: 3, **kwargs, &block)
215
- @node.call_primary(method, *command, **kwargs, &block).sum
216
- rescue RedisClient::Cluster::CommandErrorCollection => e
220
+ @node.call_primaries(method, *command, **kwargs, &block).sum
221
+ rescue RedisClient::Cluster::ErrorCollection => e
217
222
  raise if retry_count <= 0 || e.errors.values.map(&:message).grep(/ERR WAIT cannot be used with replica instances/).empty?
218
223
 
219
224
  update_cluster_info!
@@ -246,13 +251,17 @@ class RedisClient
246
251
  end
247
252
  end
248
253
 
249
- def send_cluster_command(method, *command, **kwargs, &block)
254
+ def send_cluster_command(method, *command, **kwargs, &block) # rubocop:disable Metrics/MethodLength
250
255
  subcommand = command[1].to_s.downcase
251
256
  case subcommand
252
257
  when 'addslots', 'delslots', 'failover', 'forget', 'meet', 'replicate',
253
258
  'reset', 'set-config-epoch', 'setslot'
254
259
  raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, ['cluster', subcommand]
255
260
  when 'saveconfig' then @node.call_all(method, *command, **kwargs, &block).first
261
+ when 'getkeysinslot'
262
+ raise ArgumentError, command.join(' ') if command.size != 4
263
+
264
+ find_node(@node.find_node_key_of_replica(command[2])).send(method, *command, **kwargs, &block)
256
265
  else assign_node(*command).send(method, *command, **kwargs, &block)
257
266
  end
258
267
  end
@@ -262,7 +271,7 @@ class RedisClient
262
271
  when 'debug', 'kill'
263
272
  @node.call_all(method, *command, **kwargs, &block).first
264
273
  when 'flush', 'load'
265
- @node.call_primary(method, *command, **kwargs, &block).first
274
+ @node.call_primaries(method, *command, **kwargs, &block).first
266
275
  else assign_node(*command).send(method, *command, **kwargs, &block)
267
276
  end
268
277
  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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga