redis-cluster-client 0.7.3 → 0.7.4

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: be05e560aaf9384463913ded42ed7af2be53c9439a80529bbfabc96b523d077e
4
- data.tar.gz: cf0b7ef156f19f240107c29bbb803949f9b7034052e0e9bffb668923bcf62322
3
+ metadata.gz: 82e7044600bf789f17ab9db7287beb76ebdb8c1b24c3816523da64af6a836038
4
+ data.tar.gz: ca55b62fc6a4252999f4fd0080cc267bfa31609eb8c9645265072bf374e61231
5
5
  SHA512:
6
- metadata.gz: a3bb611795108e0870668c86470a9eedce8a84bc7e80d6df974a5a35bde64de1c74fdd031969299c42f1861404b73cb02506bf83dc4ea82264548b058641c6fc
7
- data.tar.gz: 7ec956a5e98ed22bf9a7dd7428d3b4e55694a824c5d6b3acba558ac40855014eebcf3ddd286863d7393ca3356d97b1fa25c42edec8533d42750401dd93101de0
6
+ metadata.gz: fe4e0e00d82ec9afab61a96265d1f0eb6f580ce6f9b1721df1135b2b298b21c99de46f0f04cba48a5173a299896897de80037e3256ed39f9605c6f51d3c3fd0c
7
+ data.tar.gz: 956d3d22f40b00c6ec8608d06d33bb85e2ba0af810ffa68a30c51469423c7542eb52f33f71695dfe02a4c2e2577b4f870dd7684c920276adb205bf5df61630bd
@@ -7,6 +7,8 @@ require 'redis_client/cluster/normalized_cmd_name'
7
7
  class RedisClient
8
8
  class Cluster
9
9
  class Command
10
+ SLOW_COMMAND_TIMEOUT = Float(ENV.fetch('REDIS_CLIENT_SLOW_COMMAND_TIMEOUT', -1))
11
+
10
12
  EMPTY_STRING = ''
11
13
  LEFT_BRACKET = '{'
12
14
  RIGHT_BRACKET = '}'
@@ -25,7 +27,10 @@ class RedisClient
25
27
  cmd = errors = nil
26
28
 
27
29
  nodes&.each do |node|
30
+ regular_timeout = node.read_timeout
31
+ node.read_timeout = SLOW_COMMAND_TIMEOUT > 0.0 ? SLOW_COMMAND_TIMEOUT : regular_timeout
28
32
  reply = node.call('COMMAND')
33
+ node.read_timeout = regular_timeout
29
34
  commands = parse_command_reply(reply)
30
35
  cmd = ::RedisClient::Cluster::Command.new(commands)
31
36
  break
@@ -13,11 +13,18 @@ class RedisClient
13
13
  class Node
14
14
  include Enumerable
15
15
 
16
+ # It affects to strike a balance between load and stability in initialization or changed states.
17
+ MAX_STARTUP_SAMPLE = Integer(ENV.fetch('REDIS_CLIENT_MAX_STARTUP_SAMPLE', 3))
18
+
19
+ # It's used with slow queries of fetching meta data like CLUSTER NODES, COMMAND and so on.
20
+ SLOW_COMMAND_TIMEOUT = Float(ENV.fetch('REDIS_CLIENT_SLOW_COMMAND_TIMEOUT', -1))
21
+
22
+ # less memory consumption, but slow
23
+ USE_CHAR_ARRAY_SLOT = Integer(ENV.fetch('REDIS_CLIENT_USE_CHAR_ARRAY_SLOT', 1)) == 1
24
+
16
25
  SLOT_SIZE = 16_384
17
26
  MIN_SLOT = 0
18
27
  MAX_SLOT = SLOT_SIZE - 1
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
21
28
  IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
22
29
  DEAD_FLAGS = %w[fail? fail handshake noaddr noflags].freeze
23
30
  ROLE_FLAGS = %w[master slave].freeze
@@ -99,7 +106,10 @@ class RedisClient
99
106
 
100
107
  startup_nodes.each_with_index do |raw_client, i|
101
108
  work_group.push(i, raw_client) do |client|
109
+ regular_timeout = client.read_timeout
110
+ client.read_timeout = SLOW_COMMAND_TIMEOUT > 0.0 ? SLOW_COMMAND_TIMEOUT : regular_timeout
102
111
  reply = client.call('CLUSTER', 'NODES')
112
+ client.read_timeout = regular_timeout
103
113
  parse_cluster_node_reply(reply)
104
114
  rescue StandardError => e
105
115
  e
@@ -209,10 +219,6 @@ class RedisClient
209
219
  @topology.clients.each_value(&block)
210
220
  end
211
221
 
212
- def shuffled_nodes
213
- @topology.clients.values.shuffle
214
- end
215
-
216
222
  def sample
217
223
  @topology.clients.values.sample
218
224
  end
@@ -252,6 +258,10 @@ class RedisClient
252
258
  @topology.clients_for_scanning(seed: seed).values.sort_by { |c| "#{c.config.host}-#{c.config.port}" }
253
259
  end
254
260
 
261
+ def replica_clients
262
+ @topology.replica_clients.values
263
+ end
264
+
255
265
  def find_node_key_of_primary(slot)
256
266
  return if slot.nil?
257
267
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'redis_client'
4
+ require 'redis_client/cluster/normalized_cmd_name'
4
5
 
5
6
  class RedisClient
6
7
  class Cluster
@@ -22,7 +22,7 @@ class RedisClient
22
22
  @pool = pool
23
23
  @client_kwargs = kwargs
24
24
  @node = fetch_cluster_info(@config, @concurrent_worker, pool: @pool, **@client_kwargs)
25
- @command = ::RedisClient::Cluster::Command.load(@node.shuffled_nodes)
25
+ @command = ::RedisClient::Cluster::Command.load(@node.replica_clients.shuffle)
26
26
  @mutex = Mutex.new
27
27
  @command_builder = @config.command_builder
28
28
  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.3
4
+ version: 0.7.4
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-02 00:00:00.000000000 Z
11
+ date: 2023-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client