当您想使用curl时,您需要基于RESP的REST,例如webdis,tinywebdis或turbowebdis。参见https://github.com/markuman/tinywebdis#turbowebdis- tinywebdis–cherrywebdis
$ curl -w '\n' http://127.0.0.1:8888/ping
{"ping":"PONG"}
如果没有用于Redis的REST接口,则可以使用netcat为例。
$ (printf "PING\r\n";) | nc localhost 6379
+PONG
使用netcat,您必须自己构建RESP协议。参见http://redis.io/topics/protocol
我构建了一个功能强大的bash函数,该函数可以通过TCP任意代价对Redis实例执行ping操作
function redis-ping() {
# ping a redis server at any cost
redis-cli -h $1 ping 2>/dev/null || \
echo $((printf "PING\r\n";) | nc $1 6379 2>/dev/null || \
exec 3<>/dev/tcp/$1/6379 && echo -e "PING\r\n" >&3 && head -c 7 <&3)
}
用法 redis-ping localhost