Replication with Redis Cluster and multiple slaves

269 views
Skip to first unread message

goln...@gmail.com

unread,
Jan 25, 2017, 12:44:52 PM1/25/17
to Redis DB
I've been looking through redis cluster setups and still unsure about the behavior that I'm seeing. 
In my setup I currently have: 


Masters are currently bound to both the external 192.168.1.* and loopback IP (127.0.0.1)

Following the post here, I was able to join them in the cluster:

redis-cli -c -h 192.168.1.1 -p 6380 cluster meet 192.168.1.2 6380
redis
-cli -c -h 192.168.1.1 -p 6380 cluster meet 192.168.1.3 6380


And assign/distribute slots: 

for /l %s in (0, 1, 5461) do redis-cli -h 192.168.1.1 -p 6380 CLUSTER ADDSLOTS %s
for /l %s in (5462, 1, 10923) do redis-cli -h 192.168.1.2 -p 6380 CLUSTER ADDSLOTS %s
for /l %s in (10924, 1, 16383) do redis-cli -h 192.168.1.3 -p 6380 CLUSTER ADDSLOTS %s


At this point, I'm able to set/retrieve key values from any of the master, as long as I run redis-cli with the -c attribute. This is good!

Now, I would like to setup 2 slaves for each individual master (which I eventually hope to manage with Sentinel). Following the same thread, I'm still not sure what my slave configuration should be.
Since these are slaves, I'm binding them only to the loopback IP (127.0.0.1), so the configuration is as follows: 


And at this point, Slave config is purposely simple: 

bind 127.0.0.1
port
6381

dir
.

slaveof
127.0.0.1 6380

However, with this implementation, when I attempt to retrieve value assigned to another master, I'm getting a (nil). For example, when working from M1 (192.168.1.1), I'm able to set the value just fine, via the master

redis-cli -h 127.0.0.1 -p 6380 SET "SomeKey" "SomeValue" -c


But when I attempt to retrieve it from the slave on that same machine: 

redis-cli -p 6381 GET "SomeKey" -c

The return is (nil)

When I run Get on the master, I'm seeing that the value is currently located on another host: 

127.0.0.1:6380> get "SomeKey"
-> Redirected to slot [15495] located at 192.168.1.2:6380
"SomeValue"

My questions are: 
  1. Am I missing something in my slaves configuration to allow for replication from masters they're not currently assigned to?  One of responses in the post I mentioned above suggested doing cluster meet for slaves, like so:

    redis-cli -c -h 127.0.0.1 -p 6380 cluster meet 127.0.0.1:6381
    redis
    -cli -c -h 127.0.0.1 -p 6381 cluster replicate <node_id_of_6380>



    however this requires that slaves are configured with "cluster-enabled:yes", which contradicts the "slaveOf" property

  2. Is there anything else that I might be missing? 

Thanks a lot for your help! 

ma...@andyh.io

unread,
Jan 25, 2017, 7:16:02 PM1/25/17
to redi...@googlegroups.com
Hi

If you are using Redis Cluster, with `cluster-enabled:true`, you don't need Sentinel. The Redis process itself will handle the failover.

Because Redis Cluster is using `crc16` hash function to distribute the keys. If you set a key to a node, it might be ended in another node. That's the reason why you are getting nil. 

I will strongly suggest you to read the cluster tutorial on the documentation page. So you know how Redis Clusters handles keys distribution, failover and many other things.

Andy

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages