diff --git a/cluster/README.md b/cluster/README.md index f58daf2fb..d47222077 100644 --- a/cluster/README.md +++ b/cluster/README.md @@ -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 @@ -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. diff --git a/cluster/lib/redis/cluster.rb b/cluster/lib/redis/cluster.rb index 2d7183fbd..10e37e087 100644 --- a/cluster/lib/redis/cluster.rb +++ b/cluster/lib/redis/cluster.rb @@ -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, 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 diff --git a/cluster/redis-clustering.gemspec b/cluster/redis-clustering.gemspec index 31bef6100..c73c1a716 100644 --- a/cluster/redis-clustering.gemspec +++ b/cluster/redis-clustering.gemspec @@ -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