以下示例均适用于 安装在 linux 服务器上的 redis
1、通过命令检测 redis 的连通性
| ./redis-cli -p <port> -h <ip> -a <password> ping |
若是成功连接 redis ,会返回 字符串 “PONG”
#检查redis 连通性
# 0 表示redis 可正常连接 1表示连接不上
check_connectively()
{
password=`cat $HOME/conf/redis.conf |grep requirepass |grep -v '#'|awk '{print $2}'|sed 's/"//g'`
pong=`$HOME/bin/redis-cli -p $port -h 127.0.0.1 -a $password ping`
if [ "$pong" == "PONG" ];then
echo 0
else
echo 1
fi
}