|
1 | 1 | # Settings |
2 | 2 | # Make sure you run "brew install redis" |
3 | | -# Assumes you are running a Mac OS environment |
4 | | -BIN_PATH="/opt/homebrew/bin" |
| 3 | + |
| 4 | +# BIN_PATH="/opt/homebrew/bin" |
| 5 | +REDIS_CLI=`which redis-cli` |
| 6 | +REDIS_SERVER=`which redis-server` |
5 | 7 | CLUSTER_HOST=127.0.0.1 |
6 | | -PORT=6000 |
7 | | -TIMEOUT=2000 |
8 | 8 | # Creates a cluster at ports 6001-6006 with 3 masters 6001-6003 and 3 slaves 6004-6006 |
| 9 | +PORT=${2:-6000} |
| 10 | +TIMEOUT=2000 |
9 | 11 | NODES=6 |
10 | 12 | REPLICAS=1 |
11 | 13 | PROTECTED_MODE=yes |
|
24 | 26 | while [ $((PORT < ENDPORT)) != "0" ]; do |
25 | 27 | PORT=$((PORT+1)) |
26 | 28 | echo "Starting $PORT" |
27 | | - $BIN_PATH/redis-server --port $PORT --protected-mode $PROTECTED_MODE --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 ${ADDITIONAL_OPTIONS} |
| 29 | + $REDIS_SERVER --port $PORT --protected-mode $PROTECTED_MODE --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 ${ADDITIONAL_OPTIONS} |
28 | 30 | done |
29 | 31 | exit 0 |
30 | 32 | fi |
|
40 | 42 | if [ "$2" == "-f" ]; then |
41 | 43 | OPT_ARG="--cluster-yes" |
42 | 44 | fi |
43 | | - $BIN_PATH/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS $OPT_ARG |
| 45 | + $REDIS_CLI --cluster create $HOSTS --cluster-replicas $REPLICAS $OPT_ARG |
44 | 46 | exit 0 |
45 | 47 | fi |
46 | 48 |
|
|
49 | 51 | while [ $((PORT < ENDPORT)) != "0" ]; do |
50 | 52 | PORT=$((PORT+1)) |
51 | 53 | echo "Stopping $PORT" |
52 | | - $BIN_PATH/redis-cli -p $PORT shutdown nosave |
| 54 | + $REDIS_CLI -p $PORT shutdown nosave |
53 | 55 | done |
54 | 56 | exit 0 |
55 | 57 | fi |
|
60 | 62 | while [ 1 ]; do |
61 | 63 | clear |
62 | 64 | date |
63 | | - $BIN_PATH/redis-cli -p $PORT cluster nodes | head -30 |
| 65 | + $REDIS_CLI -p $PORT cluster nodes | head -30 |
64 | 66 | sleep 1 |
65 | 67 | done |
66 | 68 | exit 0 |
67 | 69 | fi |
68 | 70 |
|
69 | | -if [ "$1" == "tail" ] |
70 | | -then |
71 | | - INSTANCE=$2 |
72 | | - PORT=$((PORT+INSTANCE)) |
73 | | - tail -f ${PORT}.log |
74 | | - exit 0 |
75 | | -fi |
76 | | - |
77 | | -if [ "$1" == "tailall" ] |
78 | | -then |
79 | | - tail -f *.log |
80 | | - exit 0 |
81 | | -fi |
82 | | - |
83 | 71 | if [ "$1" == "clean" ] |
84 | 72 | then |
85 | 73 | echo "Cleaning *.log" |
|
101 | 89 | fi |
102 | 90 |
|
103 | 91 | echo "Usage: $0 [start|create|stop|watch|clean|clean-logs|call]" |
104 | | -echo "start -- Launch Redis Cluster instances." |
105 | | -echo "create [-f] -- Create a cluster using redis-cli --cluster create." |
106 | | -echo "stop -- Stop Redis Cluster instances." |
107 | | -echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node." |
108 | | -echo "clean -- Remove all instances data, logs, configs." |
109 | | -echo "clean-logs -- Remove just instances logs." |
| 92 | +echo "start [PORT] -- Launch Redis Cluster instances." |
| 93 | +echo "create [PORT] [-f] -- Create a cluster using redis-cli --cluster create." |
| 94 | +echo "stop [PORT] -- Stop Redis Cluster instances." |
| 95 | +echo "watch [PORT] -- Show CLUSTER NODES output (first 30 lines) of first node." |
| 96 | +echo "clean -- Remove all instances data, logs, configs." |
| 97 | +echo "clean-logs -- Remove just instances logs." |
0 commit comments