redis-cluster-client 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a353443838695a20f364cbc1ea043e97c65a5cdb0ba9f52b92389f61ccfd1037
4
- data.tar.gz: c927d2ad3d9a4414bc2478c2bc6c97cf038bdf68fc2eda14f7d59b390fae5467
3
+ metadata.gz: 62e1530467814b16db0fe9ddb99097a561a606d79558d199ea2c313638d1e19f
4
+ data.tar.gz: d45ab68ff666bfd2926e46ec69558cf31624525139dda7b706816461a74618a3
5
5
  SHA512:
6
- metadata.gz: 2cd2eae181262fd2aef5701ac0dcb2bdf9c70ad323ff459596ade8aba0727bd34968d9e0d1031c15b19195d094f9ae4e5376a81b8670fe79a62f7575cb5f6642
7
- data.tar.gz: 291d7cf120f00b7a78b73d5942983522a24d7441c1bcf51a0861af4d37baf5b4a15b4fd9613d33be2d4c41d37117c2ba1c4bdefc22c437a61cfa3161957e2b61
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
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.1
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-10-01 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