Skip to content

Cluster mode

Taishi Kasuga edited this page Nov 16, 2018 · 10 revisions

My English is too bad. I don't speak English very well. Let me try to write README on here before real README.md.

To deal with Redis Cluster mode is related version 4.1.0.beta1. We are waiting for real world experiences. I am using the cluster mode in production environment since 2018-08. It works.

Cluster mode support

The client is able to use Redis Cluster. You are able to specify start-up nodes.

nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" }
redis = Redis.new(cluster: nodes)

You are able to specify one node. The client internally get available nodes by CLUSTER NODES command.

redis = Redis.new(cluster: %w[redis://127.0.0.1:7000])

You are able to use scale reading.

nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" }
Redis.new(cluster: nodes, replica: true)

You are able to specify cluster option with others.

Redis.new(cluster: %w[redis://127.0.0.1:7000], timeout: 0.1)

The client automatically reconnects when failover is occurred. The client supports redirection of during resharding.

You should handle to effect to same node if you using multiple keys in multiple key allowed commands, transaction, and pipelining. You are able to use Hash Tag.

redis = Redis.new(cluster: %w[redis://127.0.0.1:7000])

redis.mget('key1', 'key2')
#=> Redis::CommandError (CROSSSLOT Keys in request don't hash to the same slot)

redis.mget('{key}1', '{key}2')
#=> [nil, nil]

The cluster mode supporting is not related Redis::Distributed. Redis::Distributed is client side consistent hashing. It is used with normal mode Redis.

Clone this wiki locally