您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

滥用cURL与Redis通信

滥用cURL与Redis通信

当您想使用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

其他 2022/1/1 18:15:47 有618人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶