redis-cluster-client 0.3.9 → 0.3.10

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: 9570ec36f046f18840242eb63ede8e5bdf710e4a9a2d738b244bed46ea53530c
4
- data.tar.gz: 5fd06dcf1f843e7f6151278400f33d45725c1ee1b8dcbf0afc6d72a00677c237
3
+ metadata.gz: 2e617645bfcf37192c1c665ceaee819439ee26821688906d311dd3792fc6c7d5
4
+ data.tar.gz: c9a3125c8d012dfc937464aa37751c26e35fa8a7696a3b418a87f7019b263a06
5
5
  SHA512:
6
- metadata.gz: 0c4b639bb180399c9d71bd054da5d10c03e93fafd4f595aa958dbec36d842a8b01da9449f5fe57f4c51a6088a99abc35fc2e6e5ec1605ba7058ecab8b05a9ebd
7
- data.tar.gz: 50b5b38b74b9b79b9526af4f76fdf7b3a5b54a51ccf2a641c78039610478087cbb0452239454580288a66c580cdacb0277f6aaf14f2eb44c5804ae6f86607b3d
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
 
@@ -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.9
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