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:'
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?
Firewall restriction is another common reason that can trigger the “could not connect to Redis connection refused”. By default Redis server listen to the TCP port 6379. If another application is using the port or if the firewall restrictions blocks the port, it can trigger the connection refused error.
By default, the Redis server runs on TCP Port 6379. If the GE Digital APM server and the Redis server are on same machine, then connections are allowed from the local server. If the GE Digital APM server and the Redis server are on different machines, then Port 6379 must be accessible between the Client and the Server.
you can do it by this way. $redis = new Redis(); $redis->connect('127.0. 0.1', 6379); echo $redis->ping(); and then check if it print +PONG , which show redis-server is running.
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"}
Without a REST interface for redis, you can use netcat for example.
$ (printf "PING\r\n";) | nc <redis-host> 6379 +PONG
For password protected redis you can use netcat like this:
$ (printf "AUTH <password>\r\n";) | nc <redis-host> 6379 +PONG
With netcat you have to build the RESP protocol by your self. See http://redis.io/topics/protocol
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) }
usage redis-ping localhost
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With