Question: What is the minimum number of nodes required in a Redis cluster?
Answer
A Redis Cluster requires a minimum of six nodes for it to operate correctly. This configuration includes three master nodes and three corresponding slave nodes, one for each master.
The reason for this setup is due to how Redis Cluster handles its failover mechanism. When a master node fails, an automatic failover process begins in which the slaves vote whether to promote one of themselves as the new master. To prevent "split-brain" scenarios where two parts of the network think they are authoritative, a majority of master nodes (at least 2 out of 3 in the case of the minimal configuration) must be able to communicate with each other and agree on the state of the network.
Here's an example of how you might start up a minimal Redis cluster:
# Start the master nodes redis-server --port 7000 --cluster-enabled yes --cluster-config-file nodes-7000.conf redis-server --port 7001 --cluster-enabled yes --cluster-config-file nodes-7001.conf redis-server --port 7002 --cluster-enabled yes --cluster-config-file nodes-7002.conf # Start the slave nodes redis-server --port 7003 --cluster-enabled yes --cluster-config-file nodes-7003.conf --cluster-slave --cluster-master-id <ID_OF_7000_NODE> redis-server --port 7004 --cluster-enabled yes --cluster-config-file nodes-7004.conf --cluster-slave --cluster-master-id <ID_OF_7001_NODE> redis-server --port 7005 --cluster-enabled yes --cluster-config-file nodes-7005.conf --cluster-slave --cluster-master-id <ID_OF_7002_NODE>
In these commands, --cluster-enabled yes
enables cluster mode, --cluster-config-file nodes-xxxx.conf
specifies a config file for each node, and --cluster-slave --cluster-master-id <ID_OF_XXXX_NODE>
sets the node as a slave of a specified master node.
Was this content helpful?
Other Common Redis Questions (and Answers)
- What is the default port used by Redis?
- How to start Redis server?
- Is Redis persistent?
- How fast is Redis?
- How to install Redis on Mac?
- How to check if Redis is running?
- How to restart Redis?
- Does Redis persist data?
- How to install Redis on Ubuntu?
- How to stop Redis server?
- How to see Redis version?
- Does Redis have tables?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost