redis-cluster-client 0.4.0 → 0.4.1

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: 780e5f1653b6633dbd4bb1bdc4f4da174d70176a5287bf6156ad5784f0612cf1
4
- data.tar.gz: ca1681357111afdc82bdf32a18985963dba85f89fd49961ac62c56075daa0cc8
3
+ metadata.gz: 3edb3d83fd54184b6e3069f156944fb1e51459dea9f72f6a149a2fba1fe1cfd8
4
+ data.tar.gz: 02fbd7531bcfcca5363351b3be60c832c43df320748f8641a39073ef6c08490a
5
5
  SHA512:
6
- metadata.gz: 4111e4b1305d955d3eb56df912debd0cfbbd388bae1d841cf1b9274a21d2e121fb511f1630d85f6c503d53ebf514503303b94402d3416517886b93f615584a22
7
- data.tar.gz: 1f6e2be52bcd834482d17bebfeead2b8d1346c954d03b61251dd973ab19f27275e53571d73ba6425dceedc34dc07cd5e6dbb98fa46de00281b6d00eeb1c87f08
6
+ metadata.gz: 9a7aece18852c1b31fad6f4d3fdd43d0201496439ce2bd5a1eea96682d916cfa99217983e96067e29dfc41001c0d35690c2c8054e9dbf299520a564d80568470
7
+ data.tar.gz: 8ba145cc9c9d017c768ae15c44483512d033ac24256bdb46953ec25a9d28d404a6d9a3297cdb31445448ee0d82cda2036328d674db6dc35fab8fe14037ebced1
@@ -14,6 +14,7 @@ class RedisClient
14
14
  class Router
15
15
  ZERO_CURSOR_FOR_SCAN = '0'
16
16
  METHODS_FOR_BLOCKING_CMD = %i[blocking_call_v blocking_call].freeze
17
+ TSF = ->(b, s) { b.nil? ? s : b.call(s) }.curry
17
18
 
18
19
  attr_reader :node
19
20
 
@@ -30,25 +31,25 @@ class RedisClient
30
31
  def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
31
32
  cmd = ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_command(command)
32
33
  case cmd
33
- when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save'
34
- @node.call_all(method, command, args, &block).first
35
- when 'flushall', 'flushdb'
36
- @node.call_primaries(method, command, args, &block).first
37
- when 'ping' then @node.send_ping(method, command, args, &block).first
34
+ when 'ping' then @node.send_ping(method, command, args).first.then(&TSF.call(block))
38
35
  when 'wait' then send_wait_command(method, command, args, &block)
39
- when 'keys' then @node.call_replicas(method, command, args, &block).flatten.sort_by(&:to_s)
40
- when 'dbsize' then @node.call_replicas(method, command, args, &block).select { |e| e.is_a?(Integer) }.sum
36
+ when 'keys' then @node.call_replicas(method, command, args).flatten.sort_by(&:to_s).then(&TSF.call(block))
37
+ when 'dbsize' then @node.call_replicas(method, command, args).select { |e| e.is_a?(Integer) }.sum.then(&TSF.call(block))
41
38
  when 'scan' then scan(command, seed: 1)
42
- when 'lastsave' then @node.call_all(method, command, args, &block).sort_by(&:to_i)
39
+ when 'lastsave' then @node.call_all(method, command, args).sort_by(&:to_i).then(&TSF.call(block))
43
40
  when 'role' then @node.call_all(method, command, args, &block)
44
41
  when 'config' then send_config_command(method, command, args, &block)
45
42
  when 'client' then send_client_command(method, command, args, &block)
46
43
  when 'cluster' then send_cluster_command(method, command, args, &block)
47
- when 'readonly', 'readwrite', 'shutdown'
48
- raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, cmd
49
44
  when 'memory' then send_memory_command(method, command, args, &block)
50
45
  when 'script' then send_script_command(method, command, args, &block)
51
46
  when 'pubsub' then send_pubsub_command(method, command, args, &block)
47
+ when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save'
48
+ @node.call_all(method, command, args).first.then(&TSF.call(block))
49
+ when 'flushall', 'flushdb'
50
+ @node.call_primaries(method, command, args).first.then(&TSF.call(block))
51
+ when 'readonly', 'readwrite', 'shutdown'
52
+ raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, cmd
52
53
  when 'discard', 'exec', 'multi', 'unwatch'
53
54
  raise ::RedisClient::Cluster::AmbiguousNodeError, cmd
54
55
  else
@@ -208,7 +209,7 @@ class RedisClient
208
209
  private
209
210
 
210
211
  def send_wait_command(method, command, args, retry_count: 3, &block) # rubocop:disable Metrics/AbcSize
211
- @node.call_primaries(method, command, args, &block).select { |r| r.is_a?(Integer) }.sum
212
+ @node.call_primaries(method, command, args).select { |r| r.is_a?(Integer) }.sum.then(&TSF.call(block))
212
213
  rescue ::RedisClient::Cluster::ErrorCollection => e
213
214
  raise if e.errors.any?(::RedisClient::CircuitBreaker::OpenCircuitError)
214
215
  raise if retry_count <= 0
@@ -224,7 +225,7 @@ class RedisClient
224
225
  def send_config_command(method, command, args, &block)
225
226
  case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
226
227
  when 'resetstat', 'rewrite', 'set'
227
- @node.call_all(method, command, args, &block).first
228
+ @node.call_all(method, command, args).first.then(&TSF.call(block))
228
229
  else assign_node(command).public_send(method, *args, command, &block)
229
230
  end
230
231
  end
@@ -232,16 +233,16 @@ class RedisClient
232
233
  def send_memory_command(method, command, args, &block)
233
234
  case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
234
235
  when 'stats' then @node.call_all(method, command, args, &block)
235
- when 'purge' then @node.call_all(method, command, args, &block).first
236
+ when 'purge' then @node.call_all(method, command, args).first.then(&TSF.call(block))
236
237
  else assign_node(command).public_send(method, *args, command, &block)
237
238
  end
238
239
  end
239
240
 
240
241
  def send_client_command(method, command, args, &block)
241
242
  case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
242
- when 'list' then @node.call_all(method, command, args, &block).flatten
243
+ when 'list' then @node.call_all(method, command, args).flatten.then(&TSF.call(block))
243
244
  when 'pause', 'reply', 'setname'
244
- @node.call_all(method, command, args, &block).first
245
+ @node.call_all(method, command, args).first.then(&TSF.call(block))
245
246
  else assign_node(command).public_send(method, *args, command, &block)
246
247
  end
247
248
  end
@@ -251,7 +252,7 @@ class RedisClient
251
252
  when 'addslots', 'delslots', 'failover', 'forget', 'meet', 'replicate',
252
253
  'reset', 'set-config-epoch', 'setslot'
253
254
  raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, ['cluster', subcommand]
254
- when 'saveconfig' then @node.call_all(method, command, args, &block).first
255
+ when 'saveconfig' then @node.call_all(method, command, args).first.then(&TSF.call(block))
255
256
  when 'getkeysinslot'
256
257
  raise ArgumentError, command.join(' ') if command.size != 4
257
258
 
@@ -260,25 +261,25 @@ class RedisClient
260
261
  end
261
262
  end
262
263
 
263
- def send_script_command(method, command, args, &block)
264
+ def send_script_command(method, command, args, &block) # rubocop:disable Metrics/AbcSize
264
265
  case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
265
266
  when 'debug', 'kill'
266
- @node.call_all(method, command, args, &block).first
267
+ @node.call_all(method, command, args).first.then(&TSF.call(block))
267
268
  when 'flush', 'load'
268
- @node.call_primaries(method, command, args, &block).first
269
+ @node.call_primaries(method, command, args).first.then(&TSF.call(block))
269
270
  when 'exists'
270
- @node.call_all(method, command, args, &block).transpose.map { |arr| arr.any?(&:zero?) ? 0 : 1 }
271
+ @node.call_all(method, command, args).transpose.map { |arr| arr.any?(&:zero?) ? 0 : 1 }.then(&TSF.call(block))
271
272
  else assign_node(command).public_send(method, *args, command, &block)
272
273
  end
273
274
  end
274
275
 
275
276
  def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
276
277
  case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
277
- when 'channels' then @node.call_all(method, command, args, &block).flatten.uniq.sort_by(&:to_s)
278
+ when 'channels' then @node.call_all(method, command, args).flatten.uniq.sort_by(&:to_s).then(&TSF.call(block))
278
279
  when 'numsub'
279
- @node.call_all(method, command, args, &block).reject(&:empty?).map { |e| Hash[*e] }
280
- .reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }
281
- when 'numpat' then @node.call_all(method, command, args, &block).select { |e| e.is_a?(Integer) }.sum
280
+ @node.call_all(method, command, args).reject(&:empty?).map { |e| Hash[*e] }
281
+ .reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }.then(&TSF.call(block))
282
+ when 'numpat' then @node.call_all(method, command, args).select { |e| e.is_a?(Integer) }.sum.then(&TSF.call(block))
282
283
  else assign_node(command).public_send(method, *args, command, &block)
283
284
  end
284
285
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-16 00:00:00.000000000 Z
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client