Question: How can you set up a Redis cluster without replication?
Answer
Setting up a Redis cluster without replication is possible but not normally recommended due to potential loss of data resilience. However, if you decide to go this route, it essentially means that each node in the cluster will hold independent data and no nodes will serve as slaves.
Here's a high level process of how you can do it:
- Start Redis Instances: You need to start different Redis instances on different ports. Here's an example command for starting a Redis instance on port 7000:
$ redis-server --port 7000 --cluster-enabled yes --cluster-config-file nodes-7000.conf --cluster-node-timeout 5000 --appendonly yes
- Create Cluster: Use the
redis-cli
tool to create the cluster after all the instances are up and running. The following example creates a cluster with nodes running on ports 7000, 7001 and 7002:
$ redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
During the creation process, the tool will ask how to distribute hash slots among nodes. By default, it offers an equal distribution. Accept this for most use cases.
- Confirm Cluster Setup: Test your cluster using the
redis-cli
command:
$ redis-cli -c -p 7000
Then in the CLI, use the 'CLUSTER NODES' command:
127.0.0.1:7000> CLUSTER NODES
If your cluster is correctly set up, it will display information about each node in the cluster.
Please note that running a Redis cluster without replication means your data won't have the redundancy typically provided by slave nodes. This makes your cluster more vulnerable to data loss if one or more nodes fail.
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