PING命令的语法如下:
PING [message]
请注意,PING命令不需要参数.如果指定了消息参数,则服务器会返回该消息.
如果连接正常,则Ping命令会返回一个"+PONG "响应.如果连接不正常,则Ping命令不会返回,或者返回一个错误或超时异常.
以下是使用Redis-cli执行PING命令的示例:
$ redis-cli
12⑦0.0.1:6379> PING
PONG
12⑦0.0.1:6379> PING "Hello World"
"Hello World"
在以下示例中,我们使用Node.js使用ioredis包执行PING命令:
const Redis = require('ioredis');
const redis = new Redis();
redis.ping((err, result) => {
if (err) {
return;
}
console.log('Result: ', result);
redis.quit();
});
输出结果:
Result: PONG
在这个例子中,我们使用telnet命令手动连接和测试Redis服务器:
$ telnet localhost 6379
Trying 12⑦0.0.1...
Connected to localhost.
Escape character is '^]'.
PING
+PONG
在这个例子中,我们手动连接到Redis服务器并执行了PING命令.服务器的响应应该是"+PONG".
以上就是土嘎嘎小编为大家整理的Redis PING命令相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!