滥用cURL与Redis通信 [英] Abuse cURL to communicate with Redis

查看:307
本文介绍了滥用cURL与Redis通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向Redis发送PING来检查连接是否正常工作,现在我可以安装redis-cli了,但我不想这样做,并且curl已经存在.那么我该如何滥用curl来做到这一点?基本上,我需要关闭此处发送的内容:

I want to send a PING to Redis to check if the connection is working, now I could just install redis-cli, but I don't want to and curl is already there. So how can I abuse curl to do that? Basically I need to turn off what's send here:

> 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,但是我找不到其他的东西.知道我该怎么做吗?

I was able to get rid of the User-Agent altogether by adding -A "", but I can't find anything else for the rest. Any idea how I can do that?

推荐答案

当您要使用curl时,您需要基于RESP的REST,例如webdis,tinywebdis或turbowebdis.参见 https://github.com/markuman/tinywebdis#turbowebdis-tinywebdis--cherrywebdis

When you want to use curl, you need REST over RESP, like webdis, tinywebdis or turbowebdis. See https://github.com/markuman/tinywebdis#turbowebdis-tinywebdis--cherrywebdis

$ curl -w '\n' http://127.0.0.1:8888/ping
{"ping":"PONG"}

没有用于Redis的REST接口,例如,您可以使用netcat.

Without a REST interface for redis, you can use netcat for example.

$ (printf "PING\r\n";) | nc localhost 6379 
+PONG

使用netcat,您必须自行构建RESP协议.参见 http://redis.io/topics/protocol

With netcat you have to build the RESP protocol by your self. See http://redis.io/topics/protocol

我已经构建了一个功能强大的bash函数,该函数可以通过tcp不惜任何代价对Redis实例执行ping操作

I've build a powerfull bash function which pings the redis instance at any cost over tcp

    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

这篇关于滥用cURL与Redis通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆