Skip to content

Commit c4254cb

Browse files
committed
Add a description about replica_affinity option for cluster gem
1 parent ce508dc commit c4254cb

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

cluster/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ If you want [the connection to be able to read from any replica](https://redis.i
3939
Redis::Cluster.new(nodes: nodes, replica: true)
4040
```
4141

42+
Also, you can specify the `:replica_affinity` option if you want to prevent accessing cross availability zones.
43+
44+
```ruby
45+
Redis::Cluster.new(nodes: nodes, replica: true, replica_affinity: :latency)
46+
```
47+
4248
The calling code is responsible for [avoiding cross slot commands](https://redis.io/topics/cluster-spec#keys-distribution-model).
4349

4450
```ruby
@@ -59,13 +65,13 @@ redis.mget('{key}1', '{key}2')
5965
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:
6066

6167
```ruby
62-
Redis.new(cluster: %w[rediss://foo.example.com:6379])
68+
Redis::Cluster.new(nodes: %w[rediss://foo.example.com:6379])
6369
```
6470

6571
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.
6672

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

7177
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.

cluster/lib/redis/cluster.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def connection
5353
# @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
5454
# @option options [Array<String, Hash{Symbol => String, Integer}>] :nodes List of cluster nodes to contact
5555
# @option options [Boolean] :replica Whether to use readonly replica nodes in Redis Cluster or not
56+
# @option options [Symbol] :replica_affinity scale reading strategy, currently supported: `:random`, `:latency`
5657
# @option options [String] :fixed_hostname Specify a FQDN if cluster mode enabled and
5758
# client has to connect nodes via single endpoint with SSL/TLS
5859
# @option options [Class] :connector Class of custom connector

cluster/redis-clustering.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ Gem::Specification.new do |s|
4747
s.required_ruby_version = '>= 2.7.0'
4848

4949
s.add_runtime_dependency('redis', s.version)
50-
s.add_runtime_dependency('redis-cluster-client', '~> 0.2')
50+
s.add_runtime_dependency('redis-cluster-client', '>= 0.3.2')
5151
end

0 commit comments

Comments
 (0)