Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a memoization bug for cluster client #1283

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cluster/lib/redis/cluster/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def initialize(*)
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)

def id
@router.node_keys.join(' ')
server_url.join(' ')
end

def server_url
@router.node_keys
@router.nil? ? @config.startup_nodes.keys : router.node_keys

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! 👋

This is related to a question I asked in https://github.com/redis-rb/redis-cluster-client/pull/364/files#r1724410379 .

I noticed that here too, the @router variable is being used directly instead of calling the router method. What's the reasoning behind this approach?

It seems that calling router would eliminate the need for the nil check. Is there a specific advantage to using @router directly in this context?

Also, I am waiting for this fix to be released!

Thanks in advance for your help!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it would be better to delay initialization if any commands aren't sent to servers in the method.

end

def connected?
Expand Down Expand Up @@ -115,9 +115,9 @@ def watch(*keys, &block)
end

handle_errors do
RedisClient::Cluster::OptimisticLocking.new(@router).watch(keys) do |c, slot, asking|
RedisClient::Cluster::OptimisticLocking.new(router).watch(keys) do |c, slot, asking|
transaction = Redis::Cluster::TransactionAdapter.new(
self, @router, @command_builder, node: c, slot: slot, asking: asking
self, router, @command_builder, node: c, slot: slot, asking: asking
)

result = yield transaction
Expand Down
2 changes: 1 addition & 1 deletion cluster/redis-clustering.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.7.0'

s.add_runtime_dependency('redis', s.version)
s.add_runtime_dependency('redis-cluster-client', '>= 0.7.11')
s.add_runtime_dependency('redis-cluster-client', '>= 0.10.0')
end
Loading