Skip to content

Cluster mode

Taishi Kasuga edited this page Jan 9, 2019 · 10 revisions

Cluster mode support

The client's version 4.1.0 and more 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 single node because 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 = Redis.new(cluster: nodes, replica: true)

You are able to specify cluster option with others.

redis = 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. It is used with normal mode Redis as cache store. Clients Supporting Consistent Hashing

Clone this wiki locally