redis-cluster-client 0.7.0 → 0.7.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a24c43fc85a464dd886dfd38358b05fbd281247e8ab2b5420aa262003419c4d3
4
- data.tar.gz: d0080c21c84bf7827bd352aac12a31fb84ba14b57e293f8275ccbb6efa96b326
3
+ metadata.gz: 62e1530467814b16db0fe9ddb99097a561a606d79558d199ea2c313638d1e19f
4
+ data.tar.gz: d45ab68ff666bfd2926e46ec69558cf31624525139dda7b706816461a74618a3
5
5
  SHA512:
6
- metadata.gz: 2b23b9967900f0ea14db0c4c2049389db73ed083304ad13641e55268a0278028fc4e231d495d65d0658125116bfd31dd47cd07394d487d7a83b0a97262d30c30
7
- data.tar.gz: 55df5f327713a8d8597dcdd63e7803b40e99610e51792f1628aa4bc2ccc6f1e0da95579a246232b328c09061d51cd448dc4a7e9f8abf97d2f06b85e7a659fe88
6
+ metadata.gz: bc22746886b90abceb446c90feab84c2c44e6ea7e7c3ff4a49c7d82192de4b9adbe0a7f17d299a2aaa2ca8e6a0c7b24b32ca4108be86d2ec2b3f2624f1922bc0
7
+ data.tar.gz: 94eec624fe7ddc302acdcc21b15923504f6ef38181d6173b77f57b4d2b1b00cafe6b341c77d444251fc557d7c0901d4a7248141ac571747c028ed59f2cb4a1fa
@@ -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_v(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' then @node.call_all(method, command, args).flatten.uniq.sort_by(&:to_s).then(&TSF.call(block))
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 'numpat' then @node.call_all(method, command, args).select { |e| e.is_a?(Integer) }.sum.then(&TSF.call(block))
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
@@ -33,11 +33,12 @@ class RedisClient
33
33
  ensure_node_key(command)
34
34
  end
35
35
 
36
- def find_node
36
+ def execute(watch: nil, &block)
37
37
  yield self
38
38
  raise ArgumentError, 'empty transaction' if @node_key.nil?
39
39
 
40
- @router.find_node(@node_key)
40
+ node = @router.find_node(@node_key)
41
+ @router.try_delegate(node, :multi, watch: watch, &block)
41
42
  end
42
43
 
43
44
  private
@@ -90,10 +90,7 @@ class RedisClient
90
90
  end
91
91
 
92
92
  def multi(watch: nil, &block)
93
- ::RedisClient::Cluster::Transaction
94
- .new(@router, @command_builder)
95
- .find_node(&block)
96
- .multi(watch: watch, &block)
93
+ ::RedisClient::Cluster::Transaction.new(@router, @command_builder).execute(watch: watch, &block)
97
94
  end
98
95
 
99
96
  def pubsub
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.0
4
+ version: 0.7.2
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-09-30 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client