Why netcat doesn't dumps the response? Why netcat doesn't dumps the response? unix unix

Why netcat doesn't dumps the response?


You may want to check the following points.

First, the line separator in Redis protocol is \r\n (and not just \n). So you need to be sure that your input file includes those characters.

Then, netcat shutdowns the connection at the end of the input file (it may therefore not wait for a Redis reply). It probably depends on the version of netcat though. On my system:

$ od -c toto.txt0000000   *   3  \n   $   3  \n   S   E   T  \n   $   4  \n   k   e   y0000020   1  \n   $   6  \n   v   a   l   u   e   1  \n   *   3  \n   $0000040   3  \n   S   E   T  \n   $   4  \n   k   e   y   2  \n   $   60000060  \n   v   a   l   u   e   2  \n$ ( sed 's/$/\r/' < toto.txt ; sleep 1 ) | netcat localhost 6379+OK+OK

The extra second gives netcat a chance to read Redis reply.

Note that redis-cli in --pipe mode is much better suited than netcat to perform massive injections through the Redis protocol.