Redis5.0.8 06 redi_shell管理脚本

vim /root/redis_shell.sh


#!/bin/bash
USAGE(){
echo "sh $0 {start|stop|restart|login|ps|tail} PORT"
}

if [ "$#" = 1 ]; then
REDIS_PORT='6379'
elif [ "$#" = 2 -a -z "$(echo "$2"|sed 's#[0-9]##g')" ]; then
REDIS_PORT="$2"
else
 USAGE
 exit 0
fi
REDIS_IP=$(hostname -I|awk '{print $1}')
PATH_DIR=/usr/local/redis_cluster/redis_${REDIS_PORT}/
PATH_CONF=/usr/local/redis_cluster/redis_${REDIS_PORT}/conf/redis_${REDIS_PORT}.conf
PATH_LOG=/usr/local/redis_cluster/redis_${REDIS_PORT}/logs/redis_${REDIS_PORT}.log

cmd_start(){
 redis-server ${PATH_CONF}
}

cmd_shutdown(){
 redis-cli -c -h $REDIS_IP -p $REDIS_PORT shutdown
}

cmd_login(){
 redis-cli -c -h $REDIS_IP -p $REDIS_PORT
}

cmd_ps(){
 ps -ef|grep redis
}

cmd_tail(){
 tail -f $PATH_LOG
}
case $1 in
 start)
 cmd_start
 cmd_ps
 ;;
 stop)
 cmd_shutdown
 cmd_ps
 ;;
 restart)
 cmd_shutdown
 cmd_start
 cmd_ps
 ;;
 login)
 cmd_login
 ;;
 ps)
 cmd_ps
 ;;
 tail)
 cmd_tail
 ;;
 *)
 USAG
esac