redis-cluster-client 0.11.5 → 0.11.6

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: 175bb2bf9b82d2b1d0b95e8d7e3e74e3952165f2edea957303f8b16716a17273
4
- data.tar.gz: 1e094b0d0ae859cb4d77cc872203c21f2f408b739a748d518fd60ca7c33e7451
3
+ metadata.gz: 9e31ae2691d5dac09f55bffb25f1a5af9f0f300d9b71246f998d7a18ad6d6d97
4
+ data.tar.gz: 7331c0ea5c04d95bb9325ad235edbede9fa872dacdcc1df2745214241600f7fa
5
5
  SHA512:
6
- metadata.gz: 8b8a13a4df4b5d96da3bcb618bada62d5882fb688b7fd7a9d618c6733a44913af24222c48d40f4db0a316d58b00aa608de99467114dac22711eb7b421f7e2e8a
7
- data.tar.gz: 2c3ebd371f3a23388e6600192a6403c5f97a90f7a7c06bab747310fa729d8be8f9d7d793763a8e7829f2e4699893d76964a96bd0ea40e727d0bdb499e1ef9f67
6
+ metadata.gz: f8752f06007254fd8c73716f3a93853062e8bb61d9381cdf66e56f705a4f7c391e0f2685ee2b75d97d2bd25aac815ae17997e0982b0774c78324b04637af1574
7
+ data.tar.gz: f995c63ae5e11ff31a0ce4feaef8c421620244c192d32ae3522a71ca62956b362962c15a87daa8c76c50018368c2851d0c99c83b6a061fa1ef7024da3df4e6fd
@@ -15,10 +15,7 @@ class RedisClient
15
15
  slot = find_slot(keys)
16
16
  raise ::RedisClient::Cluster::Transaction::ConsistencyError, "unsafe watch: #{keys.join(' ')}" if slot.nil?
17
17
 
18
- # We have not yet selected a node for this transaction, initially, which means we can handle
19
- # redirections freely initially (i.e. for the first WATCH call)
20
- node = @router.find_primary_node_by_slot(slot)
21
- handle_redirection(node, retry_count: 1) do |nd|
18
+ handle_redirection(slot, retry_count: 1) do |nd|
22
19
  nd.with do |c|
23
20
  c.ensure_connected_cluster_scoped(retryable: false) do
24
21
  c.call('ASKING') if @asking
@@ -45,10 +42,22 @@ class RedisClient
45
42
 
46
43
  private
47
44
 
48
- def handle_redirection(node, retry_count: 1, &blk)
49
- @router.handle_redirection(node, retry_count: retry_count) do |nd|
45
+ def handle_redirection(slot, retry_count: 1, &blk)
46
+ # We have not yet selected a node for this transaction, initially, which means we can handle
47
+ # redirections freely initially (i.e. for the first WATCH call)
48
+ node = @router.find_primary_node_by_slot(slot)
49
+ times_block_executed = 0
50
+ @router.handle_redirection(node, nil, retry_count: retry_count) do |nd|
51
+ times_block_executed += 1
50
52
  handle_asking_once(nd, &blk)
51
53
  end
54
+ rescue ::RedisClient::ConnectionError
55
+ # Deduct the number of retries that happened _inside_ router#handle_redirection from our remaining
56
+ # _external_ retries. Always deduct at least one in case handle_redirection raises without trying the block.
57
+ retry_count -= [times_block_executed, 1].min
58
+ raise if retry_count < 0
59
+
60
+ retry
52
61
  end
53
62
 
54
63
  def handle_asking_once(node)
@@ -90,7 +90,7 @@ class RedisClient
90
90
 
91
91
  # @see https://redis.io/docs/reference/cluster-spec/#redirection-and-resharding Redirection and resharding
92
92
  def try_send(node, method, command, args, retry_count: 3, &block)
93
- handle_redirection(node, retry_count: retry_count) do |on_node|
93
+ handle_redirection(node, command, retry_count: retry_count) do |on_node|
94
94
  if args.empty?
95
95
  # prevent memory allocation for variable-length args
96
96
  on_node.public_send(method, command, &block)
@@ -101,12 +101,12 @@ class RedisClient
101
101
  end
102
102
 
103
103
  def try_delegate(node, method, *args, retry_count: 3, **kwargs, &block)
104
- handle_redirection(node, retry_count: retry_count) do |on_node|
104
+ handle_redirection(node, nil, retry_count: retry_count) do |on_node|
105
105
  on_node.public_send(method, *args, **kwargs, &block)
106
106
  end
107
107
  end
108
108
 
109
- def handle_redirection(node, retry_count:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
109
+ def handle_redirection(node, command, retry_count:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
110
110
  yield node
111
111
  rescue ::RedisClient::CircuitBreaker::OpenCircuitError
112
112
  raise
@@ -134,6 +134,17 @@ class RedisClient
134
134
 
135
135
  retry_count -= 1
136
136
  renew_cluster_state
137
+
138
+ if retry_count >= 0
139
+ # Find the node to use for this command - if this fails for some reason, though, re-use
140
+ # the old node.
141
+ begin
142
+ node = find_node(find_node_key(command)) if command
143
+ rescue StandardError # rubocop:disable Lint/SuppressedException
144
+ end
145
+ retry
146
+ end
147
+
137
148
  retry if retry_count >= 0
138
149
  raise
139
150
  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.11.5
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-13 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client