redis-cluster-client 0.0.12 → 0.1.0
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/command.rb +4 -0
- data/lib/redis_client/cluster/pipeline.rb +3 -3
- data/lib/redis_client/cluster/pub_sub.rb +1 -1
- data/lib/redis_client/cluster/router.rb +19 -3
- data/lib/redis_client/cluster.rb +23 -6
- data/lib/redis_client/cluster_config.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 367df4e02bcd425f14da73b2ff243dfdb7fd44c6cb565bcc46952b939057904f
|
4
|
+
data.tar.gz: bfdb8033d0695fe0389563ad563c8445f9624e99ef6315e7374ee7f2e440fe40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278740e8829a1def72a411552ed7c17d0d265930c81dfc2b967cfa325a74cdbdbd0adb832dacc77e4c86c8316648695b94044cb6fdf3dd3267617d5f18b95ec1
|
7
|
+
data.tar.gz: 007bf587198b7575dabee128c0500700ef0d10c7b699a632023ce4d80fa788d2a88e851748f041ab5f6453350d7de6f9d8c96bcbc798deec7acbf37b2700ea6a
|
@@ -15,19 +15,19 @@ class RedisClient
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(*command, **kwargs)
|
18
|
-
node_key = @router.find_node_key(*command, primary_only: true)
|
18
|
+
node_key = @router.find_node_key(*command, primary_only: true, **kwargs)
|
19
19
|
@grouped[node_key] += [[@size, :call, command, kwargs]]
|
20
20
|
@size += 1
|
21
21
|
end
|
22
22
|
|
23
23
|
def call_once(*command, **kwargs)
|
24
|
-
node_key = @router.find_node_key(*command, primary_only: true)
|
24
|
+
node_key = @router.find_node_key(*command, primary_only: true, **kwargs)
|
25
25
|
@grouped[node_key] += [[@size, :call_once, command, kwargs]]
|
26
26
|
@size += 1
|
27
27
|
end
|
28
28
|
|
29
29
|
def blocking_call(timeout, *command, **kwargs)
|
30
|
-
node_key = @router.find_node_key(*command, primary_only: true)
|
30
|
+
node_key = @router.find_node_key(*command, primary_only: true, **kwargs)
|
31
31
|
@grouped[node_key] += [[@size, :blocking_call, timeout, command, kwargs]]
|
32
32
|
@size += 1
|
33
33
|
end
|
@@ -20,11 +20,13 @@ class RedisClient
|
|
20
20
|
@client_kwargs = kwargs
|
21
21
|
@node = fetch_cluster_info(@config, pool: @pool, **@client_kwargs)
|
22
22
|
@command = ::RedisClient::Cluster::Command.load(@node)
|
23
|
+
@command_builder = @config.command_builder
|
23
24
|
@mutex = Mutex.new
|
24
25
|
end
|
25
26
|
|
26
27
|
def send_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
27
28
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
29
|
+
command = @command_builder.generate!(command, kwargs)
|
28
30
|
|
29
31
|
cmd = command.first.to_s.downcase
|
30
32
|
case cmd
|
@@ -95,6 +97,8 @@ class RedisClient
|
|
95
97
|
end
|
96
98
|
|
97
99
|
def scan(*command, **kwargs) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
100
|
+
command = @command_builder.generate!(command, kwargs)
|
101
|
+
|
98
102
|
command[1] = ZERO_CURSOR_FOR_SCAN if command.size == 1
|
99
103
|
input_cursor = Integer(command[1])
|
100
104
|
|
@@ -116,12 +120,14 @@ class RedisClient
|
|
116
120
|
[((result_cursor << 8) + client_index).to_s, result_keys]
|
117
121
|
end
|
118
122
|
|
119
|
-
def assign_node(*command)
|
120
|
-
node_key = find_node_key(*command)
|
123
|
+
def assign_node(*command, **kwargs)
|
124
|
+
node_key = find_node_key(*command, **kwargs)
|
121
125
|
find_node(node_key)
|
122
126
|
end
|
123
127
|
|
124
|
-
def find_node_key(*command, primary_only: false)
|
128
|
+
def find_node_key(*command, primary_only: false, **kwargs)
|
129
|
+
command = @command_builder.generate!(command, kwargs)
|
130
|
+
|
125
131
|
key = @command.extract_first_key(command)
|
126
132
|
slot = key.empty? ? nil : ::RedisClient::Cluster::KeySlotConverter.convert(key)
|
127
133
|
|
@@ -142,6 +148,10 @@ class RedisClient
|
|
142
148
|
retry
|
143
149
|
end
|
144
150
|
|
151
|
+
def command_exists?(name)
|
152
|
+
@command.exists?(name)
|
153
|
+
end
|
154
|
+
|
145
155
|
private
|
146
156
|
|
147
157
|
def send_wait_command(method, *args, retry_count: 3, **kwargs, &block)
|
@@ -159,6 +169,7 @@ class RedisClient
|
|
159
169
|
|
160
170
|
def send_config_command(method, *args, **kwargs, &block)
|
161
171
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
172
|
+
command = @command_builder.generate!(command, kwargs)
|
162
173
|
|
163
174
|
case command[1].to_s.downcase
|
164
175
|
when 'resetstat', 'rewrite', 'set'
|
@@ -169,6 +180,7 @@ class RedisClient
|
|
169
180
|
|
170
181
|
def send_memory_command(method, *args, **kwargs, &block)
|
171
182
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
183
|
+
command = @command_builder.generate!(command, kwargs)
|
172
184
|
|
173
185
|
case command[1].to_s.downcase
|
174
186
|
when 'stats' then @node.call_all(method, *args, **kwargs, &block)
|
@@ -179,6 +191,7 @@ class RedisClient
|
|
179
191
|
|
180
192
|
def send_client_command(method, *args, **kwargs, &block)
|
181
193
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
194
|
+
command = @command_builder.generate!(command, kwargs)
|
182
195
|
|
183
196
|
case command[1].to_s.downcase
|
184
197
|
when 'list' then @node.call_all(method, *args, **kwargs, &block).flatten
|
@@ -190,6 +203,7 @@ class RedisClient
|
|
190
203
|
|
191
204
|
def send_cluster_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
192
205
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
206
|
+
command = @command_builder.generate!(command, kwargs)
|
193
207
|
subcommand = command[1].to_s.downcase
|
194
208
|
|
195
209
|
case subcommand
|
@@ -207,6 +221,7 @@ class RedisClient
|
|
207
221
|
|
208
222
|
def send_script_command(method, *args, **kwargs, &block)
|
209
223
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
224
|
+
command = @command_builder.generate!(command, kwargs)
|
210
225
|
|
211
226
|
case command[1].to_s.downcase
|
212
227
|
when 'debug', 'kill'
|
@@ -219,6 +234,7 @@ class RedisClient
|
|
219
234
|
|
220
235
|
def send_pubsub_command(method, *args, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
221
236
|
command = method == :blocking_call && args.size > 1 ? args[1..] : args
|
237
|
+
command = @command_builder.generate!(command, kwargs)
|
222
238
|
|
223
239
|
case command[1].to_s.downcase
|
224
240
|
when 'channels' then @node.call_all(method, *args, **kwargs, &block).flatten.uniq.sort_by(&:to_s)
|
data/lib/redis_client/cluster.rb
CHANGED
@@ -17,16 +17,16 @@ class RedisClient
|
|
17
17
|
"#<#{self.class.name} #{@router.node.node_keys.join(', ')}>"
|
18
18
|
end
|
19
19
|
|
20
|
-
def call(*command, **kwargs)
|
21
|
-
@router.send_command(:call, *command, **kwargs)
|
20
|
+
def call(*command, **kwargs, &block)
|
21
|
+
@router.send_command(:call, *command, **kwargs, &block)
|
22
22
|
end
|
23
23
|
|
24
|
-
def call_once(*command, **kwargs)
|
25
|
-
@router.send_command(:call_once, *command, **kwargs)
|
24
|
+
def call_once(*command, **kwargs, &block)
|
25
|
+
@router.send_command(:call_once, *command, **kwargs, &block)
|
26
26
|
end
|
27
27
|
|
28
|
-
def blocking_call(timeout, *command, **kwargs)
|
29
|
-
@router.send_command(:blocking_call, timeout, *command, **kwargs)
|
28
|
+
def blocking_call(timeout, *command, **kwargs, &block)
|
29
|
+
@router.send_command(:blocking_call, timeout, *command, **kwargs, &block)
|
30
30
|
end
|
31
31
|
|
32
32
|
def scan(*args, **kwargs, &block)
|
@@ -71,5 +71,22 @@ class RedisClient
|
|
71
71
|
@router.node.call_all(:close)
|
72
72
|
nil
|
73
73
|
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def method_missing(name, *args, **kwargs, &block)
|
78
|
+
if @router.command_exists?(name)
|
79
|
+
args.unshift(name)
|
80
|
+
return @router.send_command(:call, *args, **kwargs, &block)
|
81
|
+
end
|
82
|
+
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
86
|
+
def respond_to_missing?(name, include_private = false)
|
87
|
+
return true if @router.command_exists?(name)
|
88
|
+
|
89
|
+
super
|
90
|
+
end
|
74
91
|
end
|
75
92
|
end
|
@@ -4,6 +4,7 @@ require 'uri'
|
|
4
4
|
require 'redis_client'
|
5
5
|
require 'redis_client/cluster'
|
6
6
|
require 'redis_client/cluster/node_key'
|
7
|
+
require 'redis_client/command_builder'
|
7
8
|
|
8
9
|
class RedisClient
|
9
10
|
class ClusterConfig
|
@@ -19,11 +20,14 @@ class RedisClient
|
|
19
20
|
|
20
21
|
InvalidClientConfigError = Class.new(::RedisClient::Error)
|
21
22
|
|
23
|
+
attr_reader :command_builder
|
24
|
+
|
22
25
|
def initialize(nodes: DEFAULT_NODES, replica: false, fixed_hostname: '', **client_config)
|
23
26
|
@replica = true & replica
|
24
27
|
@fixed_hostname = fixed_hostname.to_s
|
25
28
|
@node_configs = build_node_configs(nodes.dup)
|
26
29
|
client_config = client_config.reject { |k, _| IGNORE_GENERIC_CONFIG_KEYS.include?(k) }
|
30
|
+
@command_builder = client_config.fetch(:command_builder, ::RedisClient::CommandBuilder)
|
27
31
|
@client_config = merge_generic_config(client_config, @node_configs)
|
28
32
|
@mutex = Mutex.new
|
29
33
|
end
|