I'm evaluating the cluster capabilities of Redis 3 (I'm using Redis 2 standalone at the moment), so I am reading the info at http://redis.io/topics/cluster-tutorial.
In this document I read a very important info:
Note that the minimal cluster that works as expected requires to contain at least three master nodes. For your first tests it is strongly suggested to start a six nodes cluster with three masters and three slaves.
Is it really true? 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?
I basically need one master and two slaves (so the cluster would be live if one node fails), can I have this configuration in a production environment? If yes, what are the contraindications?
Thank you very much for your help!
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
).Yes, that's why it is in the documentation :)
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.
I know that this question is old, but if someone needs a similar setup can use Master-Slaves configuration instead Cluster. You need:
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!!
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.