function usage()
{
cat<<USAGE
usage redis.sh
redis.sh start
redis.sh stop
redis.sh restart
USAGE
}
function start()
{
echo "start redis..."
redis-server /usr/local/etc/redis.conf
pong=$(echo "ping"|redis-cli)
if [[ $pong == "PONG" ]];then
echo "redis started"
else
echo "start redis failed"
fi
}
function stop()
{
echo "stopping redis..."
echo "shutdown"|redis-cli
echo "redis shutdown"
}
function restart()
{
stop
start
}
if [[ $1 == 'start' ]]; then
start
elif [[ $1 == 'stop' ]]; then
stop
elif [[ $1 == 'restart' ]];then
restart
else
usage
fi
实现了几个常用功能的,方便操作