DEV Community

Gilbert Nkolo Acquostic
Gilbert Nkolo Acquostic

Posted on

Run Redis Locally

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

To run the redis install any latest version of redis . We did the cluster setup on redis 4.0.14

First we need to create the conf file for the replication .port` we are going to use 3 master nodes and 3 slave nodes .


create 6 config files with port ranging from 7001 to 7006 .
config file for each node should be different like the below
dbfile name should be unique
port 7001
cluster-enabled yes
cluster-config-file cluster-node-1.conf cluster-node-timeout 5000
appendonly yes
appendfilename node-1.aof
dbfilename dump-1.rdb

Now we run all the redis-server by using the “redis-server” command.


redis-server node1.conf
redis-server node2.conf
redis-server node3.conf
redis-server node4.conf
redis-server node5.conf
redis-server node6.conf

You can see all nodes are running , but there is no communication between the nodes

Run the below command from the “src” folder of redis server


./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006
Once it asks for the nodes to join , please opt of “Yes” . We can see it choose node 1,2,3 as master nodes and node 4,5,6 as slave nodes

Stop one of the master node , Lets stop node 1 .

As node 1 is stopped now , we will see that one of the slave node promoted master node . for our case node 5 becomes master .

Once we start the node 1 , it will be re considered as slave node as we have already 3 master nodes available .

Similarly when you do the data replication , data will be moving from master to slave accordingly

Top comments (0)