redis-cluster-client 0.17.5 → 0.17.7

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: fb60940c0dbbb1bbf6497debd026596a02223668a8c7fa39b48055f5461db379
4
- data.tar.gz: ffbd5eaec4b8d29637d0a4d65053039e81a08477a28d1b9e201ddba355030eae
3
+ metadata.gz: '028bfbb6e37f09e90d0739017bfac62b40a98be4de93a0eb795f48f14b15c294'
4
+ data.tar.gz: 978ffaa979749f1eac72fbb926c90a37802d68d7d5d0a874a99af528ada955bf
5
5
  SHA512:
6
- metadata.gz: 4d107b60e99745a2303b0c2f7fc702baa955f4f52a7873bd6bf11ef885dbbebdb461dd8c85f6ff4387e4460a511daed69f33a813d1dac851981dd34bb25a6128
7
- data.tar.gz: bd9515f510ffe274f2e30c0fefb47729425a7a1d7a11c52f3b1ba1c331b5fd747c6a5398e553952bcf4a935f05919811e02e838ba76462b65a259e35d580ea94
6
+ metadata.gz: 761229dba60980f5380627f23ad8961a551954ea47cfe43797ab483b1fe9dfbf96cbaebe4d7fec9c3fcdf724ad781f95467f2eb5ed01d772d730cc5a9e7f256e
7
+ data.tar.gz: 1f128f1d70c0420522f482f6bcc7e884083958ce9bc905ec87bbaaeef0922c24b5ebe3489c99c352812a1b3075d3a812a213b41a10827b1427f99af93f258088
@@ -42,6 +42,14 @@ class RedisClient
42
42
  @replica_clients.freeze
43
43
  end
44
44
 
45
+ def connect_to_node(node_key, option)
46
+ return @clients[node_key] if @clients.key?(node_key)
47
+
48
+ client = build_client(node_key, option)
49
+ @clients = @clients.merge(node_key => client)
50
+ client
51
+ end
52
+
45
53
  private
46
54
 
47
55
  def disconnect_from_unwanted_nodes(options)
@@ -52,13 +60,15 @@ class RedisClient
52
60
 
53
61
  def connect_to_new_nodes(options)
54
62
  (options.keys - @clients.keys).each do |node_key|
55
- option = options[node_key].merge(@client_options)
56
- config = ::RedisClient::Cluster::Node::Config.new(scale_read: @replica_node_keys.include?(node_key), **option)
57
- client = @pool.nil? ? config.new_client : config.new_pool(**@pool)
58
- @clients[node_key] = client
63
+ @clients[node_key] = build_client(node_key, options[node_key])
59
64
  end
60
65
  end
61
66
 
67
+ def build_client(node_key, option)
68
+ config = ::RedisClient::Cluster::Node::Config.new(scale_read: @replica_node_keys.include?(node_key), **option.merge(@client_options))
69
+ @pool.nil? ? config.new_client : config.new_pool(**@pool)
70
+ end
71
+
62
72
  def make_random(seed)
63
73
  # OPTIMIZE: Figure out the most elegant way to pin a node during a pipeline or scan.
64
74
  seed.nil? ? Random : Random.new(seed)
@@ -129,6 +129,22 @@ class RedisClient
129
129
  @topology.clients.fetch(node_key)
130
130
  end
131
131
 
132
+ def find_or_connect(node_key)
133
+ client = @topology.clients[node_key]
134
+ return client unless client.nil?
135
+ raise ReloadNeeded if node_key.nil? || !@mutex.try_lock
136
+
137
+ begin
138
+ @topology.connect_to_node(node_key, @config.client_config_for_node(node_key))
139
+ ensure
140
+ @mutex.unlock
141
+ end
142
+ end
143
+
144
+ def primary_node_key?(node_key)
145
+ @replications.key?(node_key)
146
+ end
147
+
132
148
  def call_all(method, command, args, &block)
133
149
  call_multiple_nodes!(@topology.clients, method, command, args, &block)
134
150
  end
@@ -238,14 +238,16 @@ class RedisClient
238
238
 
239
239
  def assign_redirection_node(err_msg)
240
240
  _, slot, node_key = err_msg.split
241
- slot = slot.to_i
242
- @node.update_slot(slot, node_key)
243
- handle_node_reload_error { @node.find_by(node_key) }
241
+ # A MOVED to anything but a known primary means the map is behind; the reload is throttled by the jitter.
242
+ renew_cluster_state unless @node.primary_node_key?(node_key)
243
+ node = handle_node_reload_error { @node.find_or_connect(node_key) }
244
+ @node.update_slot(slot.to_i, node_key)
245
+ node
244
246
  end
245
247
 
246
248
  def assign_asking_node(err_msg)
247
249
  _, _, node_key = err_msg.split
248
- handle_node_reload_error { @node.find_by(node_key) }
250
+ handle_node_reload_error { @node.find_or_connect(node_key) }
249
251
  end
250
252
 
251
253
  def node_keys
@@ -169,7 +169,7 @@ class RedisClient
169
169
  when Hash
170
170
  parse_node_option(addr)
171
171
  else
172
- raise InvalidClientConfigError, "`nodes` option includes invalid type values: #{addr}"
172
+ raise InvalidClientConfigError, "`nodes` option includes invalid type values: #{addr.class}"
173
173
  end
174
174
  end
175
175
 
@@ -178,7 +178,7 @@ class RedisClient
178
178
 
179
179
  uri = URI(addr)
180
180
  scheme = uri.scheme || DEFAULT_SCHEME
181
- raise InvalidClientConfigError, "`nodes` option includes a invalid uri scheme: #{addr}" unless VALID_SCHEMES.include?(scheme)
181
+ raise InvalidClientConfigError, "`nodes` option includes a invalid uri scheme: #{redact_url(addr)}" unless VALID_SCHEMES.include?(scheme)
182
182
 
183
183
  username = uri.user ? URI.decode_www_form_component(uri.user) : nil
184
184
  password = uri.password ? URI.decode_www_form_component(uri.password) : nil
@@ -190,7 +190,11 @@ class RedisClient
190
190
  { ssl: scheme == SECURE_SCHEME, username: username, password: password, host: host, port: port, db: db }
191
191
  .reject { |_, v| v.nil? || v == '' || v == false }
192
192
  rescue URI::InvalidURIError => e
193
- raise InvalidClientConfigError, "#{e.message}: #{addr}"
193
+ raise InvalidClientConfigError, redact_url(e.message)
194
+ end
195
+
196
+ def redact_url(str)
197
+ str.sub(%r{//(.*)@}, '//REDACTED@')
194
198
  end
195
199
 
196
200
  def parse_node_option(addr)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.5
4
+ version: 0.17.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga