redis-cluster-client 0.13.1 → 0.13.2
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/command.rb +2 -5
- data/lib/redis_client/cluster/router.rb +49 -58
- data/lib/redis_client/cluster.rb +0 -1
- metadata +4 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96ad21a33077fd4809c93c017d75c5f0c257a666a741f329c1e61cf55f6c1cfe
|
4
|
+
data.tar.gz: 11c6d1f81a0b529682887266c0b1f0cfec305aff1f289b6d3a7b9aff6ed2151c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa59538e10f1b37b9ef4c02173b4a3a58baf7abc41cd67d18c18f94fad236aac5ffa0e51bfffc33a17a8a116f0c49aef3744b54f91f9a032a7c57d04a0d0c38
|
7
|
+
data.tar.gz: 858ade5da894495cd5c72b036be79ba58775a78ce21184d3d0425d2ad30e2d73ad501a9580bbf1ed658eebe04fac8a24d8b9b2e2b8c37d719012df0ae7c027fa
|
@@ -122,11 +122,8 @@ class RedisClient
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def determine_optional_key_position(command, option_name)
|
125
|
-
command.
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
0
|
125
|
+
i = command.index { |v| v.to_s.casecmp(option_name).zero? }
|
126
|
+
i.nil? ? 0 : i + 1
|
130
127
|
end
|
131
128
|
end
|
132
129
|
end
|
@@ -17,18 +17,57 @@ class RedisClient
|
|
17
17
|
class Router
|
18
18
|
ZERO_CURSOR_FOR_SCAN = '0'
|
19
19
|
TSF = ->(f, x) { f.nil? ? x : f.call(x) }.curry
|
20
|
+
DEDICATED_ACTIONS = lambda do # rubocop:disable Metrics/BlockLength
|
21
|
+
action = Struct.new('RedisCommandRoutingAction', :method_name, :reply_transformer, keyword_init: true)
|
22
|
+
pick_first = ->(reply) { reply.first } # rubocop:disable Style/SymbolProc
|
23
|
+
multiple_key_action = action.new(method_name: :send_multiple_keys_command)
|
24
|
+
all_node_first_action = action.new(method_name: :send_command_to_all_nodes, reply_transformer: pick_first)
|
25
|
+
primary_first_action = action.new(method_name: :send_command_to_primaries, reply_transformer: pick_first)
|
26
|
+
not_supported_action = action.new(method_name: :fail_not_supported_command)
|
27
|
+
keyless_action = action.new(method_name: :fail_keyless_command)
|
28
|
+
{
|
29
|
+
'ping' => action.new(method_name: :send_ping_command, reply_transformer: pick_first),
|
30
|
+
'wait' => action.new(method_name: :send_wait_command),
|
31
|
+
'keys' => action.new(method_name: :send_command_to_replicas, reply_transformer: ->(reply) { reply.flatten.sort_by(&:to_s) }),
|
32
|
+
'dbsize' => action.new(method_name: :send_command_to_replicas, reply_transformer: ->(reply) { reply.select { |e| e.is_a?(Integer) }.sum }),
|
33
|
+
'scan' => action.new(method_name: :send_scan_command),
|
34
|
+
'lastsave' => action.new(method_name: :send_command_to_all_nodes, reply_transformer: ->(reply) { reply.sort_by(&:to_i) }),
|
35
|
+
'role' => action.new(method_name: :send_command_to_all_nodes),
|
36
|
+
'config' => action.new(method_name: :send_config_command),
|
37
|
+
'client' => action.new(method_name: :send_client_command),
|
38
|
+
'cluster' => action.new(method_name: :send_cluster_command),
|
39
|
+
'memory' => action.new(method_name: :send_memory_command),
|
40
|
+
'script' => action.new(method_name: :send_script_command),
|
41
|
+
'pubsub' => action.new(method_name: :send_pubsub_command),
|
42
|
+
'watch' => action.new(method_name: :send_watch_command),
|
43
|
+
'mget' => multiple_key_action,
|
44
|
+
'mset' => multiple_key_action,
|
45
|
+
'del' => multiple_key_action,
|
46
|
+
'acl' => all_node_first_action,
|
47
|
+
'auth' => all_node_first_action,
|
48
|
+
'bgrewriteaof' => all_node_first_action,
|
49
|
+
'bgsave' => all_node_first_action,
|
50
|
+
'quit' => all_node_first_action,
|
51
|
+
'save' => all_node_first_action,
|
52
|
+
'flushall' => primary_first_action,
|
53
|
+
'flushdb' => primary_first_action,
|
54
|
+
'readonly' => not_supported_action,
|
55
|
+
'readwrite' => not_supported_action,
|
56
|
+
'shutdown' => not_supported_action,
|
57
|
+
'discard' => keyless_action,
|
58
|
+
'exec' => keyless_action,
|
59
|
+
'multi' => keyless_action,
|
60
|
+
'unwatch' => keyless_action
|
61
|
+
}.each_with_object({}) do |(k, v), acc|
|
62
|
+
acc[k] = v
|
63
|
+
acc[k.upcase] = v
|
64
|
+
end
|
65
|
+
end.call.freeze
|
20
66
|
|
21
|
-
private_constant :ZERO_CURSOR_FOR_SCAN, :TSF
|
67
|
+
private_constant :ZERO_CURSOR_FOR_SCAN, :TSF, :DEDICATED_ACTIONS
|
22
68
|
|
23
69
|
attr_reader :config
|
24
70
|
|
25
|
-
Action = Struct.new(
|
26
|
-
'RedisCommandRoutingAction',
|
27
|
-
:method_name,
|
28
|
-
:reply_transformer,
|
29
|
-
keyword_init: true
|
30
|
-
)
|
31
|
-
|
32
71
|
def initialize(config, concurrent_worker, pool: nil, **kwargs)
|
33
72
|
@config = config
|
34
73
|
@concurrent_worker = concurrent_worker
|
@@ -38,16 +77,15 @@ class RedisClient
|
|
38
77
|
@node.reload!
|
39
78
|
@command = ::RedisClient::Cluster::Command.load(@node.replica_clients.shuffle, slow_command_timeout: config.slow_command_timeout)
|
40
79
|
@command_builder = @config.command_builder
|
41
|
-
@dedicated_actions = build_dedicated_actions
|
42
80
|
rescue ::RedisClient::Cluster::InitialSetupError => e
|
43
81
|
e.with_config(config)
|
44
82
|
raise
|
45
83
|
end
|
46
84
|
|
47
85
|
def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
48
|
-
return assign_node_and_send_command(method, command, args, &block) unless
|
86
|
+
return assign_node_and_send_command(method, command, args, &block) unless DEDICATED_ACTIONS.key?(command.first)
|
49
87
|
|
50
|
-
action =
|
88
|
+
action = DEDICATED_ACTIONS[command.first]
|
51
89
|
return send(action.method_name, method, command, args, &block) if action.reply_transformer.nil?
|
52
90
|
|
53
91
|
reply = send(action.method_name, method, command, args)
|
@@ -257,53 +295,6 @@ class RedisClient
|
|
257
295
|
|
258
296
|
private
|
259
297
|
|
260
|
-
def build_dedicated_actions # rubocop:disable Metrics/AbcSize
|
261
|
-
pick_first = ->(reply) { reply.first } # rubocop:disable Style/SymbolProc
|
262
|
-
multiple_key_action = Action.new(method_name: :send_multiple_keys_command)
|
263
|
-
all_node_first_action = Action.new(method_name: :send_command_to_all_nodes, reply_transformer: pick_first)
|
264
|
-
primary_first_action = Action.new(method_name: :send_command_to_primaries, reply_transformer: pick_first)
|
265
|
-
not_supported_action = Action.new(method_name: :fail_not_supported_command)
|
266
|
-
keyless_action = Action.new(method_name: :fail_keyless_command)
|
267
|
-
actions = {
|
268
|
-
'ping' => Action.new(method_name: :send_ping_command, reply_transformer: pick_first),
|
269
|
-
'wait' => Action.new(method_name: :send_wait_command),
|
270
|
-
'keys' => Action.new(method_name: :send_command_to_replicas, reply_transformer: ->(reply) { reply.flatten.sort_by(&:to_s) }),
|
271
|
-
'dbsize' => Action.new(method_name: :send_command_to_replicas, reply_transformer: ->(reply) { reply.select { |e| e.is_a?(Integer) }.sum }),
|
272
|
-
'scan' => Action.new(method_name: :send_scan_command),
|
273
|
-
'lastsave' => Action.new(method_name: :send_command_to_all_nodes, reply_transformer: ->(reply) { reply.sort_by(&:to_i) }),
|
274
|
-
'role' => Action.new(method_name: :send_command_to_all_nodes),
|
275
|
-
'config' => Action.new(method_name: :send_config_command),
|
276
|
-
'client' => Action.new(method_name: :send_client_command),
|
277
|
-
'cluster' => Action.new(method_name: :send_cluster_command),
|
278
|
-
'memory' => Action.new(method_name: :send_memory_command),
|
279
|
-
'script' => Action.new(method_name: :send_script_command),
|
280
|
-
'pubsub' => Action.new(method_name: :send_pubsub_command),
|
281
|
-
'watch' => Action.new(method_name: :send_watch_command),
|
282
|
-
'mget' => multiple_key_action,
|
283
|
-
'mset' => multiple_key_action,
|
284
|
-
'del' => multiple_key_action,
|
285
|
-
'acl' => all_node_first_action,
|
286
|
-
'auth' => all_node_first_action,
|
287
|
-
'bgrewriteaof' => all_node_first_action,
|
288
|
-
'bgsave' => all_node_first_action,
|
289
|
-
'quit' => all_node_first_action,
|
290
|
-
'save' => all_node_first_action,
|
291
|
-
'flushall' => primary_first_action,
|
292
|
-
'flushdb' => primary_first_action,
|
293
|
-
'readonly' => not_supported_action,
|
294
|
-
'readwrite' => not_supported_action,
|
295
|
-
'shutdown' => not_supported_action,
|
296
|
-
'discard' => keyless_action,
|
297
|
-
'exec' => keyless_action,
|
298
|
-
'multi' => keyless_action,
|
299
|
-
'unwatch' => keyless_action
|
300
|
-
}.freeze
|
301
|
-
actions.each_with_object({}) do |(k, v), acc|
|
302
|
-
acc[k] = v
|
303
|
-
acc[k.upcase] = v
|
304
|
-
end.freeze
|
305
|
-
end
|
306
|
-
|
307
298
|
def send_command_to_all_nodes(method, command, args, &block)
|
308
299
|
@node.call_all(method, command, args, &block)
|
309
300
|
end
|
data/lib/redis_client/cluster.rb
CHANGED
@@ -19,7 +19,6 @@ class RedisClient
|
|
19
19
|
@config = config.nil? ? ClusterConfig.new(**kwargs) : config
|
20
20
|
@concurrent_worker = ::RedisClient::Cluster::ConcurrentWorker.create(**(concurrency || {}))
|
21
21
|
@command_builder = @config.command_builder
|
22
|
-
|
23
22
|
@pool = pool
|
24
23
|
@kwargs = kwargs
|
25
24
|
@router = nil
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-cluster-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taishi Kasuga
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: redis-client
|
@@ -24,7 +23,6 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0.22'
|
27
|
-
description:
|
28
26
|
email:
|
29
27
|
- proxy0721@gmail.com
|
30
28
|
executables: []
|
@@ -62,7 +60,6 @@ licenses:
|
|
62
60
|
metadata:
|
63
61
|
rubygems_mfa_required: 'true'
|
64
62
|
allowed_push_host: https://rubygems.org
|
65
|
-
post_install_message:
|
66
63
|
rdoc_options: []
|
67
64
|
require_paths:
|
68
65
|
- lib
|
@@ -77,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
74
|
- !ruby/object:Gem::Version
|
78
75
|
version: '0'
|
79
76
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
81
|
-
signing_key:
|
77
|
+
rubygems_version: 3.6.2
|
82
78
|
specification_version: 4
|
83
|
-
summary:
|
79
|
+
summary: Redis cluster-aware client for Ruby
|
84
80
|
test_files: []
|