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

Add a description about replica_affinity option for cluster gem #1150

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
10 changes: 8 additions & 2 deletions cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ If you want [the connection to be able to read from any replica](https://redis.i
Redis::Cluster.new(nodes: nodes, replica: true)
```

Also, you can specify the `:replica_affinity` option if you want to prevent accessing cross availability zones.

```ruby
Redis::Cluster.new(nodes: nodes, replica: true, replica_affinity: :latency)
```

The calling code is responsible for [avoiding cross slot commands](https://redis.io/topics/cluster-spec#keys-distribution-model).

```ruby
Expand All @@ -59,13 +65,13 @@ redis.mget('{key}1', '{key}2')
Since Redis can return FQDN of nodes in reply to client since `7.*` with CLUSTER commands, we can use cluster feature with SSL/TLS connection like this:

```ruby
Redis.new(cluster: %w[rediss://foo.example.com:6379])
Redis::Cluster.new(nodes: %w[rediss://foo.example.com:6379])
```

On the other hand, in Redis versions prior to `6.*`, you can specify options like the following if cluster mode is enabled and client has to connect to nodes via single endpoint with SSL/TLS.

```ruby
Redis.new(cluster: %w[rediss://foo-endpoint.example.com:6379], fixed_hostname: 'foo-endpoint.example.com')
Redis::Cluster.new(nodes: %w[rediss://foo-endpoint.example.com:6379], fixed_hostname: 'foo-endpoint.example.com')
```

In case of the above architecture, if you don't pass the `fixed_hostname` option to the client and servers return IP addresses of nodes, the client may fail to verify certificates.
1 change: 1 addition & 0 deletions cluster/lib/redis/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def connection
# @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
# @option options [Array<String, Hash{Symbol => String, Integer}>] :nodes List of cluster nodes to contact
# @option options [Boolean] :replica Whether to use readonly replica nodes in Redis Cluster or not
# @option options [Symbol] :replica_affinity scale reading strategy, currently supported: `:random`, `:latency`
# @option options [String] :fixed_hostname Specify a FQDN if cluster mode enabled and
# client has to connect nodes via single endpoint with SSL/TLS
# @option options [Class] :connector Class of custom connector
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.2')
s.add_runtime_dependency('redis-cluster-client', '>= 0.3.2')
end