Skip to content

Commit 3c8d9ba

Browse files
authored
chore: tiny refactoring (#374)
1 parent 46e852f commit 3c8d9ba

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Every interface handles redirections and resharding states internally.
141141
A subset of commands can be passed multiple keys.
142142
In cluster mode, these commands have a constraint that passed keys should belong to the same slot
143143
and not just the same node.
144-
Therefore, The following error occurs:
144+
Therefore, the following error occurs:
145145

146146
```
147147
$ redis-cli -c mget key1 key2 key3
@@ -194,7 +194,7 @@ r.call('mget', '{key}1', '{key}2', '{key}3')
194194

195195
This behavior is for upper libraries to be able to keep a compatibility with a standalone client.
196196
You can exploit this behavior for migrating from a standalone server to a cluster.
197-
Although multiple times queries with single-key commands are slower than pipelining,
197+
Although multiple-time queries with single-key commands are slower than pipelining,
198198
that pipelined queries are slower than a single-slot query with multiple keys.
199199
Hence, we recommend to use a hash tag in this use case for the better performance.
200200

lib/redis_client/cluster/router.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(config, concurrent_worker, pool: nil, **kwargs)
2929
@pool = pool
3030
@client_kwargs = kwargs
3131
@node = ::RedisClient::Cluster::Node.new(concurrent_worker, config: config, pool: pool, **kwargs)
32-
update_cluster_info!
32+
@node.reload!
3333
@command = ::RedisClient::Cluster::Command.load(@node.replica_clients.shuffle, slow_command_timeout: config.slow_command_timeout)
3434
@command_builder = @config.command_builder
3535
end
@@ -68,12 +68,12 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
6868
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
6969
raise
7070
rescue ::RedisClient::Cluster::Node::ReloadNeeded
71-
update_cluster_info!
71+
@node.reload!
7272
raise ::RedisClient::Cluster::NodeMightBeDown
7373
rescue ::RedisClient::Cluster::ErrorCollection => e
7474
raise if e.errors.any?(::RedisClient::CircuitBreaker::OpenCircuitError)
7575

76-
update_cluster_info! if e.errors.values.any? do |err|
76+
@node.reload! if e.errors.values.any? do |err|
7777
next false if ::RedisClient::Cluster::ErrorIdentification.identifiable?(err) && @node.none? { |c| ::RedisClient::Cluster::ErrorIdentification.client_owns_error?(err, c) }
7878

7979
err.message.start_with?('CLUSTERDOWN Hash slot not served')
@@ -119,15 +119,15 @@ def handle_redirection(node, retry_count:) # rubocop:disable Metrics/AbcSize, Me
119119
retry
120120
end
121121
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
122-
update_cluster_info!
122+
@node.reload!
123123
retry_count -= 1
124124
retry if retry_count >= 0
125125
end
126126
raise
127127
rescue ::RedisClient::ConnectionError => e
128128
raise unless ::RedisClient::Cluster::ErrorIdentification.client_owns_error?(e, node)
129129

130-
update_cluster_info!
130+
@node.reload!
131131

132132
raise if retry_count <= 0
133133

@@ -205,7 +205,7 @@ def find_node(node_key, retry_count: 3)
205205
rescue ::RedisClient::Cluster::Node::ReloadNeeded
206206
raise ::RedisClient::Cluster::NodeMightBeDown if retry_count <= 0
207207

208-
update_cluster_info!
208+
@node.reload!
209209
retry_count -= 1
210210
retry
211211
end
@@ -245,7 +245,7 @@ def send_wait_command(method, command, args, retry_count: 3, &block) # rubocop:d
245245
err.message.include?('WAIT cannot be used with replica instances')
246246
end
247247

248-
update_cluster_info!
248+
@node.reload!
249249
retry_count -= 1
250250
retry
251251
end
@@ -370,10 +370,6 @@ def send_multiple_keys_command(cmd, method, command, args, &block) # rubocop:dis
370370
end
371371
block_given? ? yield(result) : result
372372
end
373-
374-
def update_cluster_info!
375-
@node.reload!
376-
end
377373
end
378374
end
379375
end

0 commit comments

Comments
 (0)