How to deploy a Redis cluster locally

What is Redis?

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

https://redis.io/

In this set up we’ll configure and deploy a three-node Redis cluster locally.

Requirement:

Download Redis Source Code from here (You can choose the version that is best suited for the requirements): http://download.redis.io/releases/redis-5.0.5.tar.gz

Steps:

cd redis-5.0.5

# compile redis code 
make

# create 3 folders named 6001, 6002 and 6379 in the folder redis-5.0.5

mkdir 6001
mkdir 6002
mkdir 6379

# copy paste following contents into the file named redis.conf inside each of the folders 

#for node.conf in folder 6001
port 6001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

#for node.conf in folder 6002
port 6001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

#for node.conf in folder 6379
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

#Now we’ll start all Redis nodes by running the Redis server and providing a Redis configuration file we just created. # so from folder 6001 run following command

../src/redis-server ./redis.conf

You’ll get the following screen.

Repeat the same process for the rest of the nodes starting at ports 6002 and 6379

Now we create a cluster using the Redis CLI command.

cd redis-5.0.5/src

#create cluster with create cluster option 

./redis-cli --cluster create 127.0.0.1:6001 127.0.0.1:6002 127.0.0.1:6379

You’ll be greeted with the following message and it’ll create a node.conf file in respective folders and it’ll remember this configuration as long as node.conf is present in that folder. So this command is only to be used for one time.

Congratulations! Now you’re ready to use the Redis cluster. And use http://localhost:6379 to access your redis server in the clustermode.

Please note next time when you want to use the Redis cluster you just need to start the nodes and they’ll remember this configuration. You’ll only need to use the Redis server command with Redis conf option that we used in the previous steps.

About the author

Muaaz

View all posts