Skip to content

Commit

Permalink
chore: tiny refactoring (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal authored Sep 5, 2024
1 parent 46e852f commit 3c8d9ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Every interface handles redirections and resharding states internally.
A subset of commands can be passed multiple keys.
In cluster mode, these commands have a constraint that passed keys should belong to the same slot
and not just the same node.
Therefore, The following error occurs:
Therefore, the following error occurs:

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

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

Expand Down
18 changes: 7 additions & 11 deletions lib/redis_client/cluster/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(config, concurrent_worker, pool: nil, **kwargs)
@pool = pool
@client_kwargs = kwargs
@node = ::RedisClient::Cluster::Node.new(concurrent_worker, config: config, pool: pool, **kwargs)
update_cluster_info!
@node.reload!
@command = ::RedisClient::Cluster::Command.load(@node.replica_clients.shuffle, slow_command_timeout: config.slow_command_timeout)
@command_builder = @config.command_builder
end
Expand Down Expand Up @@ -68,12 +68,12 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
raise
rescue ::RedisClient::Cluster::Node::ReloadNeeded
update_cluster_info!
@node.reload!
raise ::RedisClient::Cluster::NodeMightBeDown
rescue ::RedisClient::Cluster::ErrorCollection => e
raise if e.errors.any?(::RedisClient::CircuitBreaker::OpenCircuitError)

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

err.message.start_with?('CLUSTERDOWN Hash slot not served')
Expand Down Expand Up @@ -119,15 +119,15 @@ def handle_redirection(node, retry_count:) # rubocop:disable Metrics/AbcSize, Me
retry
end
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
update_cluster_info!
@node.reload!
retry_count -= 1
retry if retry_count >= 0
end
raise
rescue ::RedisClient::ConnectionError => e
raise unless ::RedisClient::Cluster::ErrorIdentification.client_owns_error?(e, node)

update_cluster_info!
@node.reload!

raise if retry_count <= 0

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

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

update_cluster_info!
@node.reload!
retry_count -= 1
retry
end
Expand Down Expand Up @@ -370,10 +370,6 @@ def send_multiple_keys_command(cmd, method, command, args, &block) # rubocop:dis
end
block_given? ? yield(result) : result
end

def update_cluster_info!
@node.reload!
end
end
end
end

0 comments on commit 3c8d9ba

Please sign in to comment.