-
Notifications
You must be signed in to change notification settings - Fork 1k
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
.
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)
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.
irb(main):001:0> require 'redis'
=> true
irb(main):002:0> redis = Redis.new(cluster: %w[redis://127.0.0.1:7000])
=> #<Redis client v4.0.3 for redis://127.0.0.1:7000/0 redis://127.0.0.1:7001/0 redis://127.0.0.1:7002/0>
irb(main):003:0> redis.mget(:key1, :key2)
Redis::CommandError (CROSSSLOT Keys in request don't hash to the same slot)
irb(main):004:0> redis.mget('{key}1', '{key}2')
=> [nil, nil]