redis-cluster-client 0.3.8 → 0.3.10

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: 18f675a5c604e59eed84fc2b90de0b42ddfbddfe947ccdee442fdf39f379270a
4
- data.tar.gz: bf3962c29e9df010c2ef25ea226c5e041bf120ca65ae2392ab0a251a21276b44
3
+ metadata.gz: 2e617645bfcf37192c1c665ceaee819439ee26821688906d311dd3792fc6c7d5
4
+ data.tar.gz: c9a3125c8d012dfc937464aa37751c26e35fa8a7696a3b418a87f7019b263a06
5
5
  SHA512:
6
- metadata.gz: 1a8894042ac085a832548195a519095c73036d0da1ce4f3f543d675f272751fb46af42defe9a83f5dc0aea1681c1abc6b82a98c44d9b855ddbe7005a04b8cfa8
7
- data.tar.gz: ef2f92ee572dae262b3eb4e94c198e5618ad013343636fd5442d3da46b0ec48f433fd977a723d624d8a14e93a5315631ad8cb72a16ad3d46ad918186197a0070
6
+ metadata.gz: b2a815abb356acc39f0e842b5ecef6dd3d997b7554db351f7804289d386d8178221cab843e2144affceb55e849e52c672a99c49e51ef12d54000d0ee2b754f91
7
+ data.tar.gz: f19f384f8928b1487d45fb7171b4af70becc6b34a5da9a7e9dc15050d88035123f9b8e08c979c01a59fce6581337a9155d4ba1a221397a4948b1aeadceee5957
@@ -21,7 +21,7 @@ class RedisClient
21
21
  @replications.each_value { |keys| keys.sort_by! { |k| latencies.fetch(k) } }
22
22
  @replica_clients = select_replica_clients(@replications, @clients)
23
23
  @clients_for_scanning = select_clients_for_scanning(@replications, @clients)
24
- @existed_replicas = @replications.reject { |_, v| v.empty? }.values
24
+ @existed_replicas = @replications.values.reject(&:empty?)
25
25
  end
26
26
 
27
27
  def clients_for_scanning(seed: nil) # rubocop:disable Lint/UnusedMethodArgument
@@ -18,10 +18,12 @@ class RedisClient
18
18
  MAX_STARTUP_SAMPLE = 37
19
19
  MAX_THREADS = Integer(ENV.fetch('REDIS_CLIENT_MAX_THREADS', 5))
20
20
  IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
21
+ SLOT_OPTIMIZATION_STRING = '0' * SLOT_SIZE
21
22
 
22
23
  ReloadNeeded = Class.new(::RedisClient::Error)
24
+
23
25
  Info = Struct.new(
24
- 'RedisNode',
26
+ 'RedisClusterNode',
25
27
  :id, :node_key, :role, :primary_id, :ping_sent,
26
28
  :pong_recv, :config_epoch, :link_state, :slots,
27
29
  keyword_init: true
@@ -35,23 +37,27 @@ class RedisClient
35
37
  end
36
38
  end
37
39
 
38
- SLOT_OPTIMIZATION_MAX_SHARD_SIZE = 256
39
- SLOT_OPTIMIZATION_STRING = '0' * SLOT_SIZE
40
- Slot = Struct.new('RedisSlot', :slots, :primary_node_keys, keyword_init: true) do
41
- def [](slot)
42
- primary_node_keys[slots.getbyte(slot)]
40
+ Slot = Struct.new('StringArray', :string, :elements, keyword_init: true) do
41
+ def [](index)
42
+ raise IndexError if index < 0
43
+ return if index >= string.bytesize
44
+
45
+ elements[string.getbyte(index)]
43
46
  end
44
47
 
45
- def []=(slot, primary_node_key)
46
- index = primary_node_keys.find_index(primary_node_key)
47
- if index.nil?
48
- raise(::RedisClient::Cluster::Node::ReloadNeeded, primary_node_key) if primary_node_keys.size >= SLOT_OPTIMIZATION_MAX_SHARD_SIZE
48
+ def []=(index, element)
49
+ raise IndexError if index < 0
50
+ return if index >= string.bytesize
51
+
52
+ pos = elements.find_index(element) # O(N)
53
+ if pos.nil?
54
+ raise(RangeError, 'full of elements') if elements.size >= 256
49
55
 
50
- index = primary_node_keys.size
51
- primary_node_keys << primary_node_key
56
+ pos = elements.size
57
+ elements << element
52
58
  end
53
59
 
54
- slots.setbyte(slot, index)
60
+ string.setbyte(index, pos)
55
61
  end
56
62
  end
57
63
 
@@ -229,7 +235,12 @@ class RedisClient
229
235
  def update_slot(slot, node_key)
230
236
  return if @mutex.locked?
231
237
 
232
- @mutex.synchronize { @slots[slot] = node_key }
238
+ @mutex.synchronize do
239
+ @slots[slot] = node_key
240
+ rescue RangeError
241
+ @slots = Array.new(SLOT_SIZE) { |i| @slots[i] }
242
+ @slots[slot] = node_key
243
+ end
233
244
  end
234
245
 
235
246
  private
@@ -256,11 +267,11 @@ class RedisClient
256
267
  end
257
268
 
258
269
  def make_array_for_slot_node_mappings(node_info_list)
259
- return Array.new(SLOT_SIZE) if node_info_list.count(&:primary?) > SLOT_OPTIMIZATION_MAX_SHARD_SIZE
270
+ return Array.new(SLOT_SIZE) if node_info_list.count(&:primary?) > 256
260
271
 
261
272
  ::RedisClient::Cluster::Node::Slot.new(
262
- slots: String.new(SLOT_OPTIMIZATION_STRING, encoding: Encoding::BINARY, capacity: SLOT_SIZE),
263
- primary_node_keys: node_info_list.select(&:primary?).map(&:node_key)
273
+ string: String.new(SLOT_OPTIMIZATION_STRING, encoding: Encoding::BINARY, capacity: SLOT_SIZE),
274
+ elements: node_info_list.select(&:primary?).map(&:node_key)
264
275
  )
265
276
  end
266
277
 
@@ -57,11 +57,12 @@ class RedisClient
57
57
  end
58
58
 
59
59
  def normalize(name)
60
- return @cache[name] if @cache.key?(name)
60
+ return @cache[name] || name.to_s.downcase if @cache.key?(name)
61
61
  return name.to_s.downcase if @mutex.locked?
62
62
 
63
- @mutex.synchronize { @cache[name] = name.to_s.downcase }
64
- @cache[name]
63
+ str = name.to_s.downcase
64
+ @mutex.synchronize { @cache[name] = str }
65
+ str
65
66
  end
66
67
  end
67
68
  end
@@ -12,6 +12,7 @@ class RedisClient
12
12
  class Cluster
13
13
  class Router
14
14
  ZERO_CURSOR_FOR_SCAN = '0'
15
+ METHODS_FOR_BLOCKING_CMD = %i[blocking_call_v blocking_call].freeze
15
16
 
16
17
  attr_reader :node
17
18
 
@@ -91,7 +92,7 @@ class RedisClient
91
92
  raise
92
93
  end
93
94
  rescue ::RedisClient::ConnectionError => e
94
- raise if method == :blocking_call_v || (method == :blocking_call && e.is_a?(RedisClient::ReadTimeoutError))
95
+ raise if METHODS_FOR_BLOCKING_CMD.include?(method) && e.is_a?(RedisClient::ReadTimeoutError)
95
96
  raise if retry_count <= 0
96
97
 
97
98
  update_cluster_info!
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.3.8
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2022-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client