Redis cluster in Windows

Michael Maier
3 min readFeb 18, 2019

If you for some reason want to run an high-availability Redis Cluster in Windows you will need the Windows version of Redis. Luckily Microsoft has one for you: https://github.com/MicrosoftArchive/redis

The setup has minimum of 3 nodes each running one master and one slave Redis instance. The Microsoft Redis installer doesn’t include any of the Ruby scripts to setup the cluster so we will do it manually. In this example all master nodes will have port 6379 and all slaves will have port 6378. The client must be able to connect to ports 6379 and 6378 of all cluster nodes. In addition the cluster nodes must be able to connect to each other via port 16379 and 16378 (default port +10000).

Install Redis to all three nodes as Windows service by using the MSI installer. Then configure the Redis instances on all three nodes as explained below. I do not recommend this 3 node setup for production as it will require constant monitoring. If e.g. the node 1 goes down the node 2 slave 1 will take the master responsibility. This means you have master 1 and master 3 on node 2. When the node 1 is healthy again the Redis will not move the master back to node 1 unless you manually do it. This means you will now have two masters on a single node which will create a single point of failure.

Server and instance setup

Redis service is using the redis.windows-service.conf-file as the source of configuration. Enable cluster mode by uncommenting / adding the following lines (note that the cluster configuration file name reflects the port where the master instance is running):

cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000

You need to make copy of the configuration file with a new name (e.g. redis-slave.windows.conf) for the slave instance on the same node. Change the cluster-config-file -setting to reflect the port where the slave is running (e.g. nodes-6378.conf). After this start the Redis slave instance as service:

redis-server --service-install redis-slave.windows-service.conf --service-name RedisSlave --port 6378

Create the cluster by running the following commands:

redis-cli -c -h node1ip -p 6379 cluster meet node2ip 6379

redis-cli -c -h node1ip -p 6379 cluster meet node3ip 6379

redis-cli -c -h node1ip -p 6379 cluster meet node1ip 6378

redis-cli -c -h node1ip -p 6379 cluster meet node2ip 6378

redis-cli -c -h node1ip -p 6379 cluster meet node3ip 6378

In Redis you need to allocate the slots for sharding. In command prompt you can do it like this:

FOR /L %i IN (0,1,5461) DO ( redis-cli.exe -h node1ip -p 6379 CLUSTER ADDSLOTS %i )

FOR /L %i IN (5462,1,10923) DO ( redis-cli.exe -h node2ip -p 6379 CLUSTER ADDSLOTS %i )

FOR /L %i IN (10924,1,16383) DO ( redis-cli.exe -h node3ip -p 6379 CLUSTER ADDSLOTS %i )

Setup the slave replication with the following commands:

redis-cli -c -h node1ip -p 6378 cluster replicate node2id

redis-cli -c -h node2ip -p 6378 cluster replicate node3id

redis-cli -c -h node3ip -p 6378 cluster replicate node1id

You are able to get the id of the node by running the following command: redis-cli -c -h node1ip -p 6379 cluster nodes

--

--