These scripts let you run Redis in cluster mode (only for testing/dev purpose), without using the redis-trib script (written in Ruby! who wants it!?). The create-cluster
has been modified to assign cluster slots after creation.
Last active
August 6, 2020 07:03
-
-
Save pcan/09b2c3fcc5e520f072a641ebb1123172 to your computer and use it in GitHub Desktop.
Redis test cluster without ruby
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
#!/bin/bash | |
# Settings | |
PORT=30000 | |
TIMEOUT=5000 | |
NODES=3 | |
REPLICAS=1 | |
SLOTS=16384 | |
# You may want to put the above config parameters into config.sh in order to | |
# override the defaults without modifying this script. | |
if [ -a config.sh ] | |
then | |
source "config.sh" | |
fi | |
# Computed vars | |
ENDPORT=$((PORT+NODES)) | |
if [ "$1" == "start" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
echo "Starting $PORT" | |
../../src/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 --protected-mode no | |
done | |
exit 0 | |
fi | |
if [ "$1" == "create" ] | |
then | |
TMPPORT=$((PORT)) | |
while [ $((TMPPORT < ENDPORT - 1)) != "0" ]; do | |
TMPPORT=$((TMPPORT+1)) | |
echo "Meeting $((PORT+1)) with $((TMPPORT + 1))" | |
../../src/redis-cli -c -h 127.0.0.1 -p $((PORT+1)) cluster meet 127.0.0.1 $((TMPPORT + 1)) | |
done | |
SLOTSIZE=$((SLOTS / NODES)) | |
SLOTIDX=0 | |
TMPPORT=$((PORT)) | |
while [ $((TMPPORT < ENDPORT)) != "0" ]; do | |
TMPPORT=$((TMPPORT+1)) | |
IDXFROM=$((SLOTIDX)); | |
SLOTIDX=$((SLOTIDX + SLOTSIZE)) | |
if [ $((TMPPORT == ENDPORT)) != "0" ] | |
then | |
IDXTO=$((SLOTS)) | |
else | |
IDXTO=$((SLOTIDX)) | |
fi | |
echo "Clustering from $IDXFROM to $IDXTO" | |
i=$IDXFROM | |
RANGE="" | |
for ((; i<$IDXTO; i++)) do | |
RANGE="$RANGE $i" | |
done | |
../../src/redis-cli -h 127.0.0.1 -p $TMPPORT CLUSTER ADDSLOTS $RANGE | |
done | |
exit 0 | |
fi | |
if [ "$1" == "stop" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
echo "Stopping $PORT" | |
../../src/redis-cli -p $PORT shutdown nosave | |
done | |
rm *.conf | |
rm *.log | |
rm *.aof | |
exit 0 | |
fi | |
if [ "$1" == "watch" ] | |
then | |
PORT=$((PORT+1)) | |
while [ 1 ]; do | |
clear | |
date | |
../../src/redis-cli -p $PORT cluster nodes | head -30 | |
sleep 1 | |
done | |
exit 0 | |
fi | |
if [ "$1" == "tail" ] | |
then | |
INSTANCE=$2 | |
PORT=$((PORT+INSTANCE)) | |
tail -f ${PORT}.log | |
exit 0 | |
fi | |
if [ "$1" == "call" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9 | |
done | |
exit 0 | |
fi | |
if [ "$1" == "clean" ] | |
then | |
rm -rf *.log | |
rm -rf appendonly*.aof | |
rm -rf dump*.rdb | |
rm -rf nodes*.conf | |
exit 0 | |
fi | |
echo "Usage: $0 [start|create|stop|watch|tail|clean]" | |
echo "start -- Launch Redis Cluster instances." | |
echo "create -- Create a cluster using redis-trib create." | |
echo "stop -- Stop Redis Cluster instances." | |
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node." | |
echo "tail <id> -- Run tail -f of instance at base port + ID." | |
echo "clean -- Remove all instances data, logs, configs." |
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
#!/bin/bash | |
cd "${0%/*}" | |
./create-cluster start | |
sleep 1 | |
./create-cluster create | |
sleep 2 |
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
#!/bin/bash | |
cd "${0%/*}" | |
./create-cluster stop | |
sleep 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment