redis-cluster-client 0.3.2 → 0.3.3

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: 7fa6c9386e1ffd7571fdc8a29bea08960387d958149b972e1cf27d28eac98da0
4
- data.tar.gz: e532422c94e7416df967f772112c77861f4501d5dcd73c2d9893237586077677
3
+ metadata.gz: 1eaec04db89e1afa8a1d0a27688194d5941a94edb00aef979b1f368d01b4dd41
4
+ data.tar.gz: 36571e86def197fc3633d4c026958fbe635576d5f9aec3ab19b32759957a8f14
5
5
  SHA512:
6
- metadata.gz: ef29a0346608779f6528559e52e348df690baf44db0cd8c9e1fe94e44bf9d282eca81101a1246cb0bff418ec398b2b207eb47563e2b976b6523e0fe6583e55fb
7
- data.tar.gz: 7e4059d96f02c078989c7bae6cc4790f1580d0fc721c545a86d694ddae7eb90541573c67bb66a93bc6732b45b1f1ac18a3370b0d3d20df41760be9eb78255f5c
6
+ metadata.gz: 2da9f21f30cc49f9df64cf11ed5ee3c0385bc6310bbb7e8cf3478552272f716ab68928aee05bb90b24d39253040f170fd38df78687afb78ea612f310f6a96b2e
7
+ data.tar.gz: 4f7828b8072f01aaa5aa56264d7fda6f8d4ff17bce7a88a5adb2c05bd5eab8a74fe137b3c59ce1bba086a9793a05d490252d0df94228e35c6c10a2b0d869d797
@@ -72,14 +72,14 @@ class RedisClient
72
72
  end
73
73
 
74
74
  def dig_details(command, key)
75
- name = command&.flatten&.first.to_s.downcase
75
+ name = command&.flatten&.first.to_s.downcase # OPTIMIZE: prevent allocation for string
76
76
  return if name.empty? || !@details.key?(name)
77
77
 
78
78
  @details.fetch(name).fetch(key)
79
79
  end
80
80
 
81
81
  def determine_first_key_position(command) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
82
- case command&.flatten&.first.to_s.downcase
82
+ case command&.flatten&.first.to_s.downcase # OPTIMIZE: prevent allocation for string
83
83
  when 'eval', 'evalsha', 'zinterstore', 'zunionstore' then 3
84
84
  when 'object' then 2
85
85
  when 'memory'
@@ -181,6 +181,8 @@ class RedisClient
181
181
  end
182
182
 
183
183
  def update_slot(slot, node_key)
184
+ return if @mutex.locked?
185
+
184
186
  @mutex.synchronize { @slots[slot] = node_key }
185
187
  end
186
188
 
@@ -9,54 +9,48 @@ class RedisClient
9
9
  ReplySizeError = Class.new(::RedisClient::Error)
10
10
  MAX_THREADS = Integer(ENV.fetch('REDIS_CLIENT_MAX_THREADS', 5))
11
11
 
12
- def initialize(router, command_builder)
12
+ def initialize(router, command_builder, seed: Random.new_seed)
13
13
  @router = router
14
14
  @command_builder = command_builder
15
- @grouped = Hash.new([].freeze)
15
+ @grouped = {}
16
16
  @size = 0
17
- @seed = Random.new_seed
17
+ @seed = seed
18
18
  end
19
19
 
20
20
  def call(*args, **kwargs, &block)
21
21
  command = @command_builder.generate(args, kwargs)
22
22
  node_key = @router.find_node_key(command, seed: @seed)
23
- @grouped[node_key] += [[@size, :call_v, command, block]]
24
- @size += 1
23
+ add_line(node_key, [@size, :call_v, command, block])
25
24
  end
26
25
 
27
26
  def call_v(args, &block)
28
27
  command = @command_builder.generate(args)
29
28
  node_key = @router.find_node_key(command, seed: @seed)
30
- @grouped[node_key] += [[@size, :call_v, command, block]]
31
- @size += 1
29
+ add_line(node_key, [@size, :call_v, command, block])
32
30
  end
33
31
 
34
32
  def call_once(*args, **kwargs, &block)
35
33
  command = @command_builder.generate(args, kwargs)
36
34
  node_key = @router.find_node_key(command, seed: @seed)
37
- @grouped[node_key] += [[@size, :call_once_v, command, block]]
38
- @size += 1
35
+ add_line(node_key, [@size, :call_once_v, command, block])
39
36
  end
40
37
 
41
38
  def call_once_v(args, &block)
42
39
  command = @command_builder.generate(args)
43
40
  node_key = @router.find_node_key(command, seed: @seed)
44
- @grouped[node_key] += [[@size, :call_once_v, command, block]]
45
- @size += 1
41
+ add_line(node_key, [@size, :call_once_v, command, block])
46
42
  end
47
43
 
48
44
  def blocking_call(timeout, *args, **kwargs, &block)
49
45
  command = @command_builder.generate(args, kwargs)
50
46
  node_key = @router.find_node_key(command, seed: @seed)
51
- @grouped[node_key] += [[@size, :blocking_call_v, timeout, command, block]]
52
- @size += 1
47
+ add_line(node_key, [@size, :blocking_call_v, timeout, command, block])
53
48
  end
54
49
 
55
50
  def blocking_call_v(timeout, args, &block)
56
51
  command = @command_builder.generate(args)
57
52
  node_key = @router.find_node_key(command, seed: @seed)
58
- @grouped[node_key] += [[@size, :blocking_call_v, timeout, command, block]]
59
- @size += 1
53
+ add_line(node_key, [@size, :blocking_call_v, timeout, command, block])
60
54
  end
61
55
 
62
56
  def empty?
@@ -92,6 +86,14 @@ class RedisClient
92
86
 
93
87
  raise ::RedisClient::Cluster::ErrorCollection, errors
94
88
  end
89
+
90
+ private
91
+
92
+ def add_line(node_key, line)
93
+ @grouped[node_key] = [] unless @grouped.key?(node_key)
94
+ @grouped[node_key] << line
95
+ @size += 1
96
+ end
95
97
  end
96
98
  end
97
99
  end
@@ -281,6 +281,8 @@ class RedisClient
281
281
  end
282
282
 
283
283
  def update_cluster_info!
284
+ return if @mutex.locked?
285
+
284
286
  @mutex.synchronize do
285
287
  begin
286
288
  @node.each(&:close)
@@ -78,7 +78,8 @@ class RedisClient
78
78
  end
79
79
 
80
80
  def pipelined
81
- pipeline = ::RedisClient::Cluster::Pipeline.new(@router, @command_builder)
81
+ seed = @config.use_replica? && @config.replica_affinity == :random ? nil : Random.new_seed
82
+ pipeline = ::RedisClient::Cluster::Pipeline.new(@router, @command_builder, seed: seed)
82
83
  yield pipeline
83
84
  return [] if pipeline.empty? == 0
84
85
 
@@ -83,10 +83,14 @@ class RedisClient
83
83
  end
84
84
 
85
85
  def update_node(addrs)
86
+ return if @mutex.locked?
87
+
86
88
  @mutex.synchronize { @node_configs = build_node_configs(addrs) }
87
89
  end
88
90
 
89
91
  def add_node(host, port)
92
+ return if @mutex.locked?
93
+
90
94
  @mutex.synchronize { @node_configs << { host: host, port: port } }
91
95
  end
92
96
 
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.2
4
+ version: 0.3.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: 2022-09-07 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client