redis-cluster-client 0.11.1 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/pub_sub.rb +33 -23
- data/lib/redis_client/cluster/router.rb +9 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a18bda4b076ac6a39e7558b39b0ff5f443e2f9d192ff45ee6749e64b3a349fbd
|
4
|
+
data.tar.gz: ed166898e6dbb23b316d87162767fe06eb34440029bdb6f33764c58038c20d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1ca4265e58d3d4cdb00c0ad9629d72dec6c1a0681d34663e38adb147a0d66985be3f4257d6f6d0c62752cda0f710bfd9e7eb9f3694e07ec4796ce99677c148
|
7
|
+
data.tar.gz: 178592be6e79bfdf2c5288f558fca21116aabd98cc10b4436298393d22f895844523b3e32f28635172229a404c55d83e52e242230677ab00d509dba7d70adc0c
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'redis_client'
|
4
|
+
require 'redis_client/cluster/errors'
|
4
5
|
require 'redis_client/cluster/normalized_cmd_name'
|
5
6
|
|
6
7
|
class RedisClient
|
@@ -89,12 +90,11 @@ class RedisClient
|
|
89
90
|
|
90
91
|
case event = @queue.pop(true)
|
91
92
|
when ::RedisClient::CommandError
|
92
|
-
|
93
|
-
@router.renew_cluster_state
|
94
|
-
break start_over
|
95
|
-
end
|
93
|
+
raise event unless event.message.start_with?('MOVED', 'CLUSTERDOWN Hash slot not served')
|
96
94
|
|
97
|
-
|
95
|
+
break start_over
|
96
|
+
when ::RedisClient::ConnectionError
|
97
|
+
break start_over
|
98
98
|
when StandardError then raise event
|
99
99
|
when Array then break event
|
100
100
|
end
|
@@ -114,25 +114,20 @@ class RedisClient
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
def call_to_single_state(command
|
117
|
+
def call_to_single_state(command)
|
118
118
|
node_key = @router.find_node_key(command)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@router.renew_cluster_state
|
125
|
-
retry_count -= 1
|
126
|
-
retry_count >= 0 ? retry : raise
|
119
|
+
|
120
|
+
handle_connection_error(node_key) do
|
121
|
+
@state_dict[node_key] ||= State.new(@router.find_node(node_key).pubsub, @queue)
|
122
|
+
@state_dict[node_key].call(command)
|
123
|
+
end
|
127
124
|
end
|
128
125
|
|
129
126
|
def call_to_all_states(command)
|
130
127
|
@state_dict.each do |node_key, state|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
@state_dict.delete(node_key)
|
135
|
-
@router.renew_cluster_state
|
128
|
+
handle_connection_error(node_key, ignore: true) do
|
129
|
+
state.call(command)
|
130
|
+
end
|
136
131
|
end
|
137
132
|
end
|
138
133
|
|
@@ -152,11 +147,26 @@ class RedisClient
|
|
152
147
|
timeout.nil? || timeout < 0 ? 0 : timeout * 1_000_000
|
153
148
|
end
|
154
149
|
|
150
|
+
def handle_connection_error(node_key, ignore: false)
|
151
|
+
yield
|
152
|
+
rescue ::RedisClient::ConnectionError
|
153
|
+
@state_dict[node_key]&.close
|
154
|
+
@state_dict.delete(node_key)
|
155
|
+
@router.renew_cluster_state
|
156
|
+
raise unless ignore
|
157
|
+
end
|
158
|
+
|
155
159
|
def start_over
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
+
loop do
|
161
|
+
@router.renew_cluster_state
|
162
|
+
@state_dict.each_value(&:close)
|
163
|
+
@state_dict.clear
|
164
|
+
@queue.clear
|
165
|
+
@commands.each { |command| _call(command) }
|
166
|
+
break
|
167
|
+
rescue ::RedisClient::ConnectionError, ::RedisClient::Cluster::NodeMightBeDown
|
168
|
+
sleep 1.0
|
169
|
+
end
|
160
170
|
end
|
161
171
|
end
|
162
172
|
end
|
@@ -29,7 +29,7 @@ class RedisClient
|
|
29
29
|
@pool = pool
|
30
30
|
@client_kwargs = kwargs
|
31
31
|
@node = ::RedisClient::Cluster::Node.new(concurrent_worker, config: config, pool: pool, **kwargs)
|
32
|
-
|
32
|
+
@node.reload!
|
33
33
|
@command = ::RedisClient::Cluster::Command.load(@node.replica_clients.shuffle, slow_command_timeout: config.slow_command_timeout)
|
34
34
|
@command_builder = @config.command_builder
|
35
35
|
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
|
@@ -236,6 +241,8 @@ class RedisClient
|
|
236
241
|
|
237
242
|
def renew_cluster_state
|
238
243
|
@node.reload!
|
244
|
+
rescue ::RedisClient::Cluster::InitialSetupError
|
245
|
+
# ignore
|
239
246
|
end
|
240
247
|
|
241
248
|
def close
|
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.
|
4
|
+
version: 0.11.3
|
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-09-
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|