Permalink
Browse files

extract all comands to functions

  • Loading branch information...
jdvr committed Jul 27, 2017
1 parent 384cebe commit 7fcbb59a1350d6bbda88747a318df8dd3a93d5df
Showing with 73 additions and 37 deletions.
  1. +73 −37 create-cluster
View
@@ -20,6 +20,14 @@ redis-server() {
../../src/redis-server $@
}
redis-trib() {
../../src/redis-trib.rb $@
}
redis-cli() {
../../src/redis-cli $@
}
start_command() {
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
@@ -29,74 +37,102 @@ start_command() {
exit 0
}
create_command() {
HOSTS=""
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
HOSTS="$HOSTS 127.0.0.1:$PORT"
done
redis-trib create --replicas $REPLICAS $HOSTS
exit 0
}
stop_command() {
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Stopping $PORT"
redis-cli -p $PORT shutdown nosave
done
exit 0
}
watch_command() {
PORT=$((PORT+1))
while [ 1 ]; do
clear
date
redis-cli -p $PORT cluster nodes | head -30
sleep 1
done
exit 0
}
tail_command() {
INSTANCE=$2
PORT=$((PORT+INSTANCE))
tail -f ${PORT}.log
exit 0
}
call_command() {
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
done
exit 0
}
clean_command() {
rm -rf *.log
rm -rf appendonly*.aof
rm -rf dump*.rdb
rm -rf nodes*.conf
exit 0
}
clean_logs_command() {
rm -rf *.log
exit 0
}
if [ "$1" == "start" ]
then
start_command
fi
if [ "$1" == "create" ]
then
HOSTS=""
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
HOSTS="$HOSTS 127.0.0.1:$PORT"
done
../../src/redis-trib.rb create --replicas $REPLICAS $HOSTS
exit 0
create_command
fi
if [ "$1" == "stop" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Stopping $PORT"
../../src/redis-cli -p $PORT shutdown nosave
done
exit 0
stop_command
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
watch_command
fi
if [ "$1" == "tail" ]
then
INSTANCE=$2
PORT=$((PORT+INSTANCE))
tail -f ${PORT}.log
exit 0
tail_command
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
call_command
fi
if [ "$1" == "clean" ]
then
rm -rf *.log
rm -rf appendonly*.aof
rm -rf dump*.rdb
rm -rf nodes*.conf
exit 0
clean_command
fi
if [ "$1" == "clean-logs" ]
then
rm -rf *.log
exit 0
clean_logs_command
fi
echo "Usage: $0 [start|create|stop|watch|tail|clean]"

0 comments on commit 7fcbb59

Please sign in to comment.