redis-cluster-client 0.7.1 → 0.7.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/node.rb +2 -1
- data/lib/redis_client/cluster/pub_sub.rb +23 -0
- 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: be05e560aaf9384463913ded42ed7af2be53c9439a80529bbfabc96b523d077e
|
4
|
+
data.tar.gz: cf0b7ef156f19f240107c29bbb803949f9b7034052e0e9bffb668923bcf62322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3bb611795108e0870668c86470a9eedce8a84bc7e80d6df974a5a35bde64de1c74fdd031969299c42f1861404b73cb02506bf83dc4ea82264548b058641c6fc
|
7
|
+
data.tar.gz: 7ec956a5e98ed22bf9a7dd7428d3b4e55694a824c5d6b3acba558ac40855014eebcf3ddd286863d7393ca3356d97b1fa25c42edec8533d42750401dd93101de0
|
@@ -17,6 +17,7 @@ class RedisClient
|
|
17
17
|
MIN_SLOT = 0
|
18
18
|
MAX_SLOT = SLOT_SIZE - 1
|
19
19
|
MAX_STARTUP_SAMPLE = Integer(ENV.fetch('REDIS_CLIENT_MAX_STARTUP_SAMPLE', 3))
|
20
|
+
USE_CHAR_ARRAY_SLOT = Integer(ENV.fetch('REDIS_CLIENT_USE_CHAR_ARRAY_SLOT', 1)) == 1 # less memory consumption, but slow
|
20
21
|
IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
|
21
22
|
DEAD_FLAGS = %w[fail? fail handshake noaddr noflags].freeze
|
22
23
|
ROLE_FLAGS = %w[master slave].freeze
|
@@ -310,7 +311,7 @@ class RedisClient
|
|
310
311
|
end
|
311
312
|
|
312
313
|
def make_array_for_slot_node_mappings(node_info_list)
|
313
|
-
return Array.new(SLOT_SIZE) if node_info_list.count(&:primary?) > 256
|
314
|
+
return Array.new(SLOT_SIZE) if !USE_CHAR_ARRAY_SLOT || node_info_list.count(&:primary?) > 256
|
314
315
|
|
315
316
|
primary_node_keys = node_info_list.select(&:primary?).map(&:node_key)
|
316
317
|
::RedisClient::Cluster::Node::CharArray.new(SLOT_SIZE, primary_node_keys)
|
@@ -52,10 +52,12 @@ class RedisClient
|
|
52
52
|
|
53
53
|
def call(*args, **kwargs)
|
54
54
|
_call(@command_builder.generate(args, kwargs))
|
55
|
+
nil
|
55
56
|
end
|
56
57
|
|
57
58
|
def call_v(command)
|
58
59
|
_call(@command_builder.generate(command))
|
60
|
+
nil
|
59
61
|
end
|
60
62
|
|
61
63
|
def close
|
@@ -86,10 +88,31 @@ class RedisClient
|
|
86
88
|
private
|
87
89
|
|
88
90
|
def _call(command)
|
91
|
+
case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_command(command)
|
92
|
+
when 'subscribe', 'psubscribe', 'ssubscribe' then call_to_single_state(command)
|
93
|
+
when 'unsubscribe', 'punsubscribe' then call_to_all_states(command)
|
94
|
+
when 'sunsubscribe' then call_for_sharded_states(command)
|
95
|
+
else call_to_single_state(command)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def call_to_single_state(command)
|
89
100
|
node_key = @router.find_node_key(command)
|
90
101
|
try_call(node_key, command)
|
91
102
|
end
|
92
103
|
|
104
|
+
def call_to_all_states(command)
|
105
|
+
@state_dict.each_value { |s| s.call(command) }
|
106
|
+
end
|
107
|
+
|
108
|
+
def call_for_sharded_states(command)
|
109
|
+
if command.size == 1
|
110
|
+
call_to_all_states(command)
|
111
|
+
else
|
112
|
+
call_to_single_state(command)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
93
116
|
def try_call(node_key, command, retry_count: 1)
|
94
117
|
add_state(node_key).call(command)
|
95
118
|
rescue ::RedisClient::CommandError => e
|
@@ -288,11 +288,18 @@ class RedisClient
|
|
288
288
|
|
289
289
|
def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
290
290
|
case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
|
291
|
-
when 'channels'
|
291
|
+
when 'channels'
|
292
|
+
@node.call_all(method, command, args).flatten.uniq.sort_by(&:to_s).then(&TSF.call(block))
|
293
|
+
when 'shardchannels'
|
294
|
+
@node.call_replicas(method, command, args).flatten.uniq.sort_by(&:to_s).then(&TSF.call(block))
|
295
|
+
when 'numpat'
|
296
|
+
@node.call_all(method, command, args).select { |e| e.is_a?(Integer) }.sum.then(&TSF.call(block))
|
292
297
|
when 'numsub'
|
293
298
|
@node.call_all(method, command, args).reject(&:empty?).map { |e| Hash[*e] }
|
294
299
|
.reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }.then(&TSF.call(block))
|
295
|
-
when '
|
300
|
+
when 'shardnumsub'
|
301
|
+
@node.call_replicas(method, command, args).reject(&:empty?).map { |e| Hash[*e] }
|
302
|
+
.reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }.then(&TSF.call(block))
|
296
303
|
else assign_node(command).public_send(method, *args, command, &block)
|
297
304
|
end
|
298
305
|
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.7.
|
4
|
+
version: 0.7.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: 2023-10-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|