我想发送一个 PING
到 Redis 以检查连接是否正常,现在我可以安装 redis-cli
,但我不想和 curl
已经在那里了。那么我该如何滥用 curl
来做到这一点?基本上我需要关闭这里发送的内容:
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:6379
> Accept: */*
>
-ERR wrong number of arguments for 'get' command
-ERR unknown command 'User-Agent:'
-ERR unknown command 'Host:'
-ERR unknown command 'Accept:'
通过添加 -A ""
User-Agent
但我找不到其他任何东西。知道我该怎么做吗?
原文由 Mahoni 发布,翻译遵循 CC BY-SA 4.0 许可协议
当你想使用 curl 时,你需要 REST over RESP,比如 webdis、tinywebdis 或 turbowebdis。见 https://github.com/markuman/tinywebdis#turbowebdis-tinywebdis–cherrywebdis
如果没有 redis 的 REST 接口,您可以使用 netcat 例如。
对于受密码保护的 redis,您可以像这样使用 netcat:
使用 netcat,您必须自己构建 RESP 协议。见 http://redis.io/topics/protocol
更新 2018-01-09
我已经构建了一个强大的 bash 函数,它可以通过 tcp 不惜一切代价 ping redis 实例
用法
redis-ping localhost