Last active
October 9, 2019 23:18
-
-
Save jakeonfire/8d3e6abda4ac8001fbc0bf7f70f04a3e to your computer and use it in GitHub Desktop.
Run a redis cluster as part of a docker compose configuration (for testing and development). The below sets up 3 masters with 1 replica each.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
redis-cluster: | |
image: redis | |
expose: | |
- '7000-7005' | |
environment: | |
- PORT=7000 | |
- NODES=6 | |
- REPLICAS=1 | |
- TIMEOUT=5000 | |
command: > | |
/usr/bin/env bash -c ' | |
function ctrl_c() { | |
echo "Exiting!" | |
exit | |
} | |
trap "ctrl_c" SIGINT | |
# adapted from redis-5.0.5/utils/create-cluster/create-cluster (start & create) | |
ENDPORT=$$((PORT + NODES)) | |
HOSTS="" | |
IP=$$(hostname -I) | |
IP=$$(echo $${IP}) # trim whitespace | |
while [[ $$((PORT < ENDPORT)) != "0" ]]; do | |
echo "Starting $$PORT..." | |
redis-server --port $$PORT --cluster-enabled yes --cluster-config-file nodes-$${PORT}.conf --cluster-node-timeout $$TIMEOUT --appendonly yes --appendfilename appendonly-$${PORT}.aof --dbfilename dump-$${PORT}.rdb --logfile $${PORT}.log --daemonize yes | |
HOSTS="$$HOSTS $$IP:$$PORT" | |
PORT=$$((PORT+1)) | |
done | |
echo "yes" | eval redis-cli --cluster create $$HOSTS --cluster-replicas $$REPLICAS | |
tail -f *.log | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment