Question: How can you set up a Redis cluster with 2 nodes?

Answer

Setting up a Redis cluster with two nodes involves the following steps:

  1. Install Redis: You need to install Redis on each node. Use your OS package manager, or download and compile Redis from source.
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make
  1. Configure each Redis instance for clustering: Modify the redis.conf file for each instance. Set the cluster-enabled option to yes, specify a cluster-config-file, and provide a cluster-node-timeout.
# redis.conf cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes
  1. Start the Redis instances: Start each Redis instance using their specific redis.conf files.
src/redis-server /path/to/redis.conf
  1. Create the Cluster: Use the redis-cli utility to create the cluster. Consider the IP addresses are 192.168.1.1 and 192.168.1.2 and they are both running Redis on port 7000.
redis-cli --cluster create 192.168.1.1:7000 192.168.1.2:7000
  1. Follow the prompts: The redis-cli utility will propose a configuration. Accept it.

Please note that Redis cluster requires at least three master nodes for robust failover and distributed storage. A cluster with only two nodes does not guarantee high availability. It's better to use a setup with at least three nodes if you want high availability and partition tolerance.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.