redis-cluster-client 0.0.8 → 0.0.9
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 +4 -4
- data/lib/redis_client/cluster/node.rb +9 -9
- data/lib/redis_client/cluster.rb +57 -44
- 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: 032431ff16773725b9cb68482bc5df78affdf23e66b6bbd91b6ddbabdd9da921
|
4
|
+
data.tar.gz: dc789f59f6509e35ab23df03a70867b5e8414ee3bb327462fbcd5d63be4c6744
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6013ff65d8dc06b776b7b201244d75eaf62993368f5285d823472f78bec2c81639734f23c32793bc1b8d1981905e5794e35e4e353696d70f1d66930434e6104f
|
7
|
+
data.tar.gz: 0e1dc5f17a9706c2fc64bdd03e74ee457f9b9aea81740cdeb5459bd9bbc769b6353047b64ef008b6d34b950fbc7cb8cf57e66c9deb41d33edbacaba78ca2a12e
|
@@ -129,9 +129,9 @@ class RedisClient
|
|
129
129
|
@clients.fetch(node_key)
|
130
130
|
end
|
131
131
|
|
132
|
-
def call_all(method, *
|
132
|
+
def call_all(method, *args, **kwargs, &block)
|
133
133
|
results, errors = try_map do |_, client|
|
134
|
-
client.send(method, *
|
134
|
+
client.send(method, *args, **kwargs, &block)
|
135
135
|
end
|
136
136
|
|
137
137
|
return results.values if errors.empty?
|
@@ -139,11 +139,11 @@ class RedisClient
|
|
139
139
|
raise ::RedisClient::Cluster::ErrorCollection, errors
|
140
140
|
end
|
141
141
|
|
142
|
-
def call_primaries(method, *
|
142
|
+
def call_primaries(method, *args, **kwargs, &block)
|
143
143
|
results, errors = try_map do |node_key, client|
|
144
144
|
next if replica?(node_key)
|
145
145
|
|
146
|
-
client.send(method, *
|
146
|
+
client.send(method, *args, **kwargs, &block)
|
147
147
|
end
|
148
148
|
|
149
149
|
return results.values if errors.empty?
|
@@ -151,14 +151,14 @@ class RedisClient
|
|
151
151
|
raise ::RedisClient::Cluster::ErrorCollection, errors
|
152
152
|
end
|
153
153
|
|
154
|
-
def call_replicas(method, *
|
155
|
-
return call_primaries(method, *
|
154
|
+
def call_replicas(method, *args, **kwargs, &block)
|
155
|
+
return call_primaries(method, *args, **kwargs, &block) if replica_disabled?
|
156
156
|
|
157
157
|
replica_node_keys = @replications.values.map(&:sample)
|
158
158
|
results, errors = try_map do |node_key, client|
|
159
159
|
next if primary?(node_key) || !replica_node_keys.include?(node_key)
|
160
160
|
|
161
|
-
client.send(method, *
|
161
|
+
client.send(method, *args, **kwargs, &block)
|
162
162
|
end
|
163
163
|
|
164
164
|
return results.values if errors.empty?
|
@@ -166,9 +166,9 @@ class RedisClient
|
|
166
166
|
raise ::RedisClient::Cluster::ErrorCollection, errors
|
167
167
|
end
|
168
168
|
|
169
|
-
def send_ping(method, *
|
169
|
+
def send_ping(method, *args, **kwargs, &block)
|
170
170
|
results, errors = try_map do |_, client|
|
171
|
-
client.send(method, *
|
171
|
+
client.send(method, *args, **kwargs, &block)
|
172
172
|
end
|
173
173
|
|
174
174
|
return results.values if errors.empty?
|
data/lib/redis_client/cluster.rb
CHANGED
@@ -127,8 +127,7 @@ class RedisClient
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def blocking_call(timeout, *command, **kwargs)
|
130
|
-
|
131
|
-
try_send(node, :blocking_call, timeout, *command, **kwargs)
|
130
|
+
send_command(:blocking_call, timeout, *command, **kwargs)
|
132
131
|
end
|
133
132
|
|
134
133
|
def scan(*args, **kwargs, &block)
|
@@ -186,41 +185,43 @@ class RedisClient
|
|
186
185
|
node_info: node_info, pool: pool, with_replica: config.use_replica?, **kwargs)
|
187
186
|
end
|
188
187
|
|
189
|
-
def send_command(method, *
|
188
|
+
def send_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
189
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
190
|
+
|
190
191
|
cmd = command.first.to_s.downcase
|
191
192
|
case cmd
|
192
193
|
when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save'
|
193
|
-
@node.call_all(method, *
|
194
|
+
@node.call_all(method, *args, **kwargs, &block).first
|
194
195
|
when 'flushall', 'flushdb'
|
195
|
-
@node.call_primaries(method, *
|
196
|
-
when 'ping' then @node.send_ping(method, *
|
197
|
-
when 'wait' then send_wait_command(method, *
|
198
|
-
when 'keys' then @node.call_replicas(method, *
|
199
|
-
when 'dbsize' then @node.call_replicas(method, *
|
196
|
+
@node.call_primaries(method, *args, **kwargs, &block).first
|
197
|
+
when 'ping' then @node.send_ping(method, *args, **kwargs, &block).first
|
198
|
+
when 'wait' then send_wait_command(method, *args, **kwargs, &block)
|
199
|
+
when 'keys' then @node.call_replicas(method, *args, **kwargs, &block).flatten.sort
|
200
|
+
when 'dbsize' then @node.call_replicas(method, *args, **kwargs, &block).sum
|
200
201
|
when 'scan' then _scan(*command, **kwargs)
|
201
|
-
when 'lastsave' then @node.call_all(method, *
|
202
|
-
when 'role' then @node.call_all(method, *
|
203
|
-
when 'config' then send_config_command(method, *
|
204
|
-
when 'client' then send_client_command(method, *
|
205
|
-
when 'cluster' then send_cluster_command(method, *
|
202
|
+
when 'lastsave' then @node.call_all(method, *args, **kwargs, &block).sort
|
203
|
+
when 'role' then @node.call_all(method, *args, **kwargs, &block)
|
204
|
+
when 'config' then send_config_command(method, *args, **kwargs, &block)
|
205
|
+
when 'client' then send_client_command(method, *args, **kwargs, &block)
|
206
|
+
when 'cluster' then send_cluster_command(method, *args, **kwargs, &block)
|
206
207
|
when 'readonly', 'readwrite', 'shutdown'
|
207
208
|
raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, cmd
|
208
|
-
when 'memory' then send_memory_command(method, *
|
209
|
-
when 'script' then send_script_command(method, *
|
210
|
-
when 'pubsub' then send_pubsub_command(method, *
|
209
|
+
when 'memory' then send_memory_command(method, *args, **kwargs, &block)
|
210
|
+
when 'script' then send_script_command(method, *args, **kwargs, &block)
|
211
|
+
when 'pubsub' then send_pubsub_command(method, *args, **kwargs, &block)
|
211
212
|
when 'discard', 'exec', 'multi', 'unwatch'
|
212
213
|
raise ::RedisClient::Cluster::AmbiguousNodeError, cmd
|
213
214
|
else
|
214
215
|
node = assign_node(*command)
|
215
|
-
try_send(node, method, *
|
216
|
+
try_send(node, method, *args, **kwargs, &block)
|
216
217
|
end
|
217
218
|
rescue RedisClient::Cluster::Node::ReloadNeeded
|
218
219
|
update_cluster_info!
|
219
220
|
raise ::RedisClient::Cluster::NodeMightBeDown
|
220
221
|
end
|
221
222
|
|
222
|
-
def send_wait_command(method, *
|
223
|
-
@node.call_primaries(method, *
|
223
|
+
def send_wait_command(method, *args, retry_count: 3, **kwargs, &block)
|
224
|
+
@node.call_primaries(method, *args, **kwargs, &block).sum
|
224
225
|
rescue RedisClient::Cluster::ErrorCollection => e
|
225
226
|
raise if retry_count <= 0
|
226
227
|
raise if e.errors.values.none? do |err|
|
@@ -232,64 +233,76 @@ class RedisClient
|
|
232
233
|
retry
|
233
234
|
end
|
234
235
|
|
235
|
-
def send_config_command(method, *
|
236
|
+
def send_config_command(method, *args, **kwargs, &block)
|
237
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
238
|
+
|
236
239
|
case command[1].to_s.downcase
|
237
240
|
when 'resetstat', 'rewrite', 'set'
|
238
|
-
@node.call_all(method, *
|
239
|
-
else assign_node(*command).send(method, *
|
241
|
+
@node.call_all(method, *args, **kwargs, &block).first
|
242
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
240
243
|
end
|
241
244
|
end
|
242
245
|
|
243
|
-
def send_memory_command(method, *
|
246
|
+
def send_memory_command(method, *args, **kwargs, &block)
|
247
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
248
|
+
|
244
249
|
case command[1].to_s.downcase
|
245
|
-
when 'stats' then @node.call_all(method, *
|
246
|
-
when 'purge' then @node.call_all(method, *
|
247
|
-
else assign_node(*command).send(method, *
|
250
|
+
when 'stats' then @node.call_all(method, *args, **kwargs, &block)
|
251
|
+
when 'purge' then @node.call_all(method, *args, **kwargs, &block).first
|
252
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
248
253
|
end
|
249
254
|
end
|
250
255
|
|
251
|
-
def send_client_command(method, *
|
256
|
+
def send_client_command(method, *args, **kwargs, &block)
|
257
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
258
|
+
|
252
259
|
case command[1].to_s.downcase
|
253
|
-
when 'list' then @node.call_all(method, *
|
260
|
+
when 'list' then @node.call_all(method, *args, **kwargs, &block).flatten
|
254
261
|
when 'pause', 'reply', 'setname'
|
255
|
-
@node.call_all(method, *
|
256
|
-
else assign_node(*command).send(method, *
|
262
|
+
@node.call_all(method, *args, **kwargs, &block).first
|
263
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
257
264
|
end
|
258
265
|
end
|
259
266
|
|
260
|
-
def send_cluster_command(method, *
|
267
|
+
def send_cluster_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
268
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
261
269
|
subcommand = command[1].to_s.downcase
|
270
|
+
|
262
271
|
case subcommand
|
263
272
|
when 'addslots', 'delslots', 'failover', 'forget', 'meet', 'replicate',
|
264
273
|
'reset', 'set-config-epoch', 'setslot'
|
265
274
|
raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, ['cluster', subcommand]
|
266
|
-
when 'saveconfig' then @node.call_all(method, *
|
275
|
+
when 'saveconfig' then @node.call_all(method, *args, **kwargs, &block).first
|
267
276
|
when 'getkeysinslot'
|
268
277
|
raise ArgumentError, command.join(' ') if command.size != 4
|
269
278
|
|
270
|
-
find_node(@node.find_node_key_of_replica(command[2])).send(method, *
|
271
|
-
else assign_node(*command).send(method, *
|
279
|
+
find_node(@node.find_node_key_of_replica(command[2])).send(method, *args, **kwargs, &block)
|
280
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
272
281
|
end
|
273
282
|
end
|
274
283
|
|
275
|
-
def send_script_command(method, *
|
284
|
+
def send_script_command(method, *args, **kwargs, &block)
|
285
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
286
|
+
|
276
287
|
case command[1].to_s.downcase
|
277
288
|
when 'debug', 'kill'
|
278
|
-
@node.call_all(method, *
|
289
|
+
@node.call_all(method, *args, **kwargs, &block).first
|
279
290
|
when 'flush', 'load'
|
280
|
-
@node.call_primaries(method, *
|
281
|
-
else assign_node(*command).send(method, *
|
291
|
+
@node.call_primaries(method, *args, **kwargs, &block).first
|
292
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
282
293
|
end
|
283
294
|
end
|
284
295
|
|
285
|
-
def send_pubsub_command(method, *
|
296
|
+
def send_pubsub_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
297
|
+
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
298
|
+
|
286
299
|
case command[1].to_s.downcase
|
287
|
-
when 'channels' then @node.call_all(method, *
|
300
|
+
when 'channels' then @node.call_all(method, *args, **kwargs, &block).flatten.uniq.sort
|
288
301
|
when 'numsub'
|
289
|
-
@node.call_all(method, *
|
302
|
+
@node.call_all(method, *args, **kwargs, &block).reject(&:empty?).map { |e| Hash[*e] }
|
290
303
|
.reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }
|
291
|
-
when 'numpat' then @node.call_all(method, *
|
292
|
-
else assign_node(*command).send(method, *
|
304
|
+
when 'numpat' then @node.call_all(method, *args, **kwargs, &block).sum
|
305
|
+
else assign_node(*command).send(method, *args, **kwargs, &block)
|
293
306
|
end
|
294
307
|
end
|
295
308
|
|
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.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taishi Kasuga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|