Redis cluster: 3 master nodes minimum?
Solution 1:
Is it really true?
Yes, that's why it is in the documentation :)
In my mind this is correct if I would use sharding capabilities (data are shared between nodes), but what if I don't need it and I would be happy of having data on only one node?
Using Redis in cluster mode means sharding. If you're happy with a single instance, simply don't use the cluster. Otherwise, refer to the cluster specification itself to understand more about the underlying assumptions. Specifically, in the case of minimal cluster configuration, you'll want 3 masters to ensure the cluster's availability in case of a partition, or else you won't be able to agree on majority.
Solution 2:
Is it really true?
No. It's not really true. It's a strong recommendation (as you can tell from the "that works as expected" language; if you don't expect your data to be durable, and you expect it to disappear, etc. - you can set up a single node cluster. Why you would instead of just turning cluster mode off... that's up to you.)
So, yes, you can set up a single-node cluster, even though it isn't advised (for all the reasons mentioned in other answers and the documentation.) There is nothing in the redis cluster code that will stop you, other than a check in the redis-trib.rb helper that's there to dissuade naive users.
To get around that check, and set up a single node cluster (if you're sure that is what you want - remember, it almost certainly isn't), you can either manually assign the shards to your node with CLUSTER ADDSLOTS 1 2 3 ...
(etc, for all 16384 shards). Or use the Python version of redis-trib which doesn't have the 3-node safety check (redis-trib.py create 127.0.0.1:6379
).
Solution 3:
I know that this question is old, but if someone needs a similar setup can use Master-Slaves configuration instead Cluster. You need:
- 2 Redis server at least
- 3 Redis Sentinel to monit the health and avoid Split-Brain
- A way to check who's the master (I use HAProxy on client server with some check commands)
If you can made it smart enough, you can just write to master and read from all the nodes. I use this setup on some Wordpress sites but the plugin is not made to detect who's the master, so I just use HAProxy to detect the master and send all trafic to that node. If master node dies, an Slave node takes the master role (redis-sentinel manage that). HAProxy detects that master has changed and then change the node that receive all the traffic.
Sorry for don't post code and examples, but now I can't to do it.
Greetings!!
Solution 4:
If you rely on Redis to fail over, you need a minimal of three master nodes and three slave nodes (a minimal of 3 servers, each running a master and a slave).
If you use external cluster software, for example heartbeat, you can setup two nodes, one being master and one being slave in cluster mode, allocate all 16384 slots to the master, and use failover scripts to "CLUSTER FAILOVER TAKEOVER" when the master is DOWN. Of course you may also setup a service IP to failover together with redis. This additional arrangement allows you to use non-cluster redis client as well.
Production run for one year and fail over a few times (machine reboot for kernel update) and so far no problem reported from operation team.