Skip to content

Instantly share code, notes, and snippets.

@eeddaann
Created July 4, 2018 08:03
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eeddaann/6e2b70e36f7586a556487f663b97760e to your computer and use it in GitHub Desktop.
Save eeddaann/6e2b70e36f7586a556487f663b97760e to your computer and use it in GitHub Desktop.
Test connection to Redis with netcat

Test connection to Redis with netcat

echo -e '*1\r\n$4\r\nPING\r\n' | nc redis.host.com 6379

@ccesara
Copy link

ccesara commented Feb 28, 2019

Thanks!

@ilyaevseev
Copy link

ilyaevseev commented Sep 30, 2019

Fix:

{ echo -e '*1\r\n$4\r\nPING\r\n'; sleep 1; } | netcat redis.host.com 6379

Or:

echo -e '*1\r\n$4\r\nPING\r\n' | netcat -w1 127.0.0.1 6379

Without sleep or "-w1", netcat is killed by closed pipe before response received.

@harry-wood
Copy link

Yeah I saw it working about 1 time in 5, but the sleep fixes that. Or this command works instantly:

exec 3<>/dev/tcp/redis.host.com/6379 && echo -e "PING\r\n" >&3 && head -c 7 <&3

That's from this answer which uses a file descriptor bash tcp trick

@franee
Copy link

franee commented May 3, 2023

Thanks!

If redis has a password:

$ echo -e 'AUTH password-here\r\n*1\r\n$4\r\nPING\r\n' | nc -w1 127.0.0.1 6379
+OK
+PONG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment