redis-swarm-cluster

SAVE THE BELOW SCRIPT AND RUN IN SWARM CLUSTER TO CREATE REDIS CLUSTER

#!/bin/bash

# @pre-requisite SWARM CLUSTER

# @usage ./redis.sh

# @function - Creates a 6 node cluster with 3 master and 3 slave.

REDIS_CONFIG='port 6379

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes'

docker network create -d overlay --attachable redisnet

network=redisnet

docker service create --name redis \

--network $network \

--replicas=6 \

-e REDIS_CONFIG="$REDIS_CONFIG" \

-e REDIS_CONFIG_FILE="/usr/local/etc/redis/redis.conf" \

knowesis/redis:4.0.8 sh -c 'mkdir -p $(dirname $REDIS_CONFIG_FILE) && echo "$REDIS_CONFIG" > $REDIS_CONFIG_FILE && cat $REDIS_CONFIG_FILE && redis-server $REDIS_CONFIG_FILE'

sleep 2

docker service ps redis --no-trunc

docker run -it --rm --net $network knowesis/ruby:1.0 sh -c "\

ruby redis-trib.rb create --replicas 1 \

\$(getent hosts tasks.redis | awk '{print \$1 \":6379\"}') "