redis-cluster-client 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dbfbaf304e900620662da7b8b5e6af36dfda8dc62a27d3e9a1efb975f5bd07f
4
- data.tar.gz: 8080422513db9f7edcbad4d3eafc4fb0472d5a754ee2a0bc64eaacfda8e283e0
3
+ metadata.gz: ee9d2adeb89553bf3e1bfdb3d98f1dabed5a9e4347bee756776081036a1d4341
4
+ data.tar.gz: 9576cdbb916ee5b1ea82b722bb41a8144f46bbd4641620c41822c89be85bcf34
5
5
  SHA512:
6
- metadata.gz: 980a40227b929c64632ff903ad4334942489d3c2af13ef0ec09006be856ae7c06a2e96c1a4c8c9a976b38091f53aa2e87833a5d6d04c07a0426129da20924838
7
- data.tar.gz: b7915e5337c66a3a0423ebcb206e7be0b3794ce1ccac40a1a99e08b8f305a594c9594d6a670f3679d1df081e80527fde4a153ac6949c7ca832bbb149fc0dcfee
6
+ metadata.gz: 99ba847297a711cb7f1af1c05da9cf4222d00c3c89a91e4ba92b8e7eb5078275db448b46ce573b97e9fa03e40fd7cb69deac0987a43fc6be3dc3b53ea9779024
7
+ data.tar.gz: 8755ce77dfad1fc86fdb17ce63a31aa5eb71fa8aba44a84eea3194c29d2df2045dfeab48d60137d9e1032ec1cfc42a66aef732c48ba005f38da4a687c084ec8a
@@ -33,6 +33,7 @@ class RedisClient
33
33
  'keys' => RoutingAction.new(method_name: :send_command_to_replicas, reply_transformer: FLATTEN_STRINGS),
34
34
  'dbsize' => RoutingAction.new(method_name: :send_command_to_replicas, reply_transformer: SUM_NUM),
35
35
  'scan' => RoutingAction.new(method_name: :send_scan_command),
36
+ 'bless' => RoutingAction.new(method_name: :send_bless_command),
36
37
  'lastsave' => RoutingAction.new(method_name: :send_command_to_all_nodes, reply_transformer: SORT_NUMBERS),
37
38
  'role' => RoutingAction.new(method_name: :send_command_to_all_nodes),
38
39
  'config' => RoutingAction.new(method_name: :send_config_command),
@@ -39,16 +39,9 @@ class RedisClient
39
39
 
40
40
  def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
41
41
  action = @dedicated_actions[command.first]
42
- if action.nil?
43
- cmd_spec = @command.get_spec(command)
44
- action = find_policy_action(cmd_spec)
45
- return assign_node_and_send_command(method, command, args, cmd_spec: cmd_spec, &block) if action.nil?
46
- end
47
-
48
- return send(action.method_name, method, command, args, &block) if action.reply_transformer.nil?
42
+ return send_command_by_spec(method, command, args, &block) if action.nil?
49
43
 
50
- reply = send(action.method_name, method, command, args)
51
- action.reply_transformer.call(reply).then(&TSF.call(block))
44
+ send_command_by_action(action, method, command, args, &block)
52
45
  rescue ::RedisClient::CircuitBreaker::OpenCircuitError
53
46
  raise
54
47
  rescue ::RedisClient::Cluster::Node::ReloadNeeded
@@ -133,9 +126,9 @@ class RedisClient
133
126
  retry
134
127
  end
135
128
 
136
- def scan(command, seed: nil) # rubocop:disable Metrics/AbcSize
137
- command[1] = ZERO_CURSOR_FOR_SCAN if command.size == 1
138
- input_cursor = Integer(command[1])
129
+ def scan(command, seed: nil, cursor_index: 1) # rubocop:disable Metrics/AbcSize
130
+ command[cursor_index] = ZERO_CURSOR_FOR_SCAN if command.size == cursor_index
131
+ input_cursor = Integer(command[cursor_index])
139
132
 
140
133
  client_index = input_cursor % 256
141
134
  raw_cursor = input_cursor >> 8
@@ -145,7 +138,7 @@ class RedisClient
145
138
  client = clients[client_index]
146
139
  return [ZERO_CURSOR_FOR_SCAN, []] unless client
147
140
 
148
- command[1] = raw_cursor.to_s
141
+ command[cursor_index] = raw_cursor.to_s
149
142
 
150
143
  result_cursor, result_keys = client.call_v(command)
151
144
  result_cursor = Integer(result_cursor)
@@ -258,6 +251,22 @@ class RedisClient
258
251
 
259
252
  private
260
253
 
254
+ # Follows the command tips which the server reports, or the routing by the key.
255
+ def send_command_by_spec(method, command, args, &block)
256
+ cmd_spec = @command.get_spec(command)
257
+ action = find_policy_action(cmd_spec)
258
+ return assign_node_and_send_command(method, command, args, cmd_spec: cmd_spec, &block) if action.nil?
259
+
260
+ send_command_by_action(action, method, command, args, &block)
261
+ end
262
+
263
+ def send_command_by_action(action, method, command, args, &block)
264
+ return send(action.method_name, method, command, args, &block) if action.reply_transformer.nil?
265
+
266
+ reply = send(action.method_name, method, command, args)
267
+ action.reply_transformer.call(reply).then(&TSF.call(block))
268
+ end
269
+
261
270
  def find_policy_action(cmd_spec)
262
271
  return if cmd_spec.nil?
263
272
 
@@ -327,6 +336,15 @@ class RedisClient
327
336
  end
328
337
  end
329
338
 
339
+ def send_bless_command(method, command, args, &block)
340
+ if command[1].casecmp('scan').zero?
341
+ scan(command, seed: 1, cursor_index: 2).then(&TSF.call(block))
342
+ else
343
+ # The other subcommands keep the default routing with the redirection handling.
344
+ send_command_by_spec(method, command, args, &block)
345
+ end
346
+ end
347
+
330
348
  def send_memory_command(method, command, args, &block)
331
349
  if command[1].casecmp('stats').zero?
332
350
  @node.call_all(method, command, args, &block)
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.17.1
4
+ version: 0.17.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 4.0.16
78
+ rubygems_version: 4.0.20
79
79
  specification_version: 4
80
80
  summary: Redis cluster-aware client for Ruby
81
81
  test_files: []