Why isn't netcat dumping a response?

$ cat mass_insert.txt *3 $3 SET $4 key1 $6 value1 *3 $3 SET $4 key2 $6 value2 $ cat mass_insert.txt | nc localhost 6379 

If you see, I have redis commands to bulk paste into the mass_insert.text file, I am cat in netcat, and the commands receive a fine to redis message, but the response is not reset. Question: WHY?

A simple google.com HEAD request with netcat works just fine, i.e. resets the answer -

 $ printf "HEAD / HTTP/1.0\r\n\r\n" | nc google.com 80 HTTP/1.0 302 Found Location: http://www.google.co.in/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=cac6fac8de9b5d0c:FF=0:TM=1365352115:LM=1365352115:S=CVuSzOK8mrsfFczI; expires=Tue, 07-Apr-2015 16:28:35 GMT; path=/; domain=.google.com Set-Cookie: NID=67=K5KjAFxuDP5epZKDdvSf4oCe4FRP1AL8LG_9MEdsArn4Oz_UBG69H0KOMUiKLuVN-hH4NIUvHOLgmfh_82P5v6Nh-sGFrGXyCnQz0zD-Sj_QbzxQ6NIK0rahsxjvyTn7; expires=Mon, 07-Oct-2013 16:28:35 GMT; path=/; domain=.google.com; HttpOnly P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info." Date: Sun, 07 Apr 2013 16:28:35 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN 
+4
source share
1 answer

You can check the following points.

First, the line separator in the Redis protocol is \ r \ n (and not just \ n). Therefore, you must be sure that your input file contains these characters.

Then netcat disconnects the connection at the end of the input file (therefore, it may not wait for Redis to respond). This probably depends on the version of netcat. In my system:

 $ od -c toto.txt 0000000 * 3 \n $ 3 \n SET \n $ 4 \nkey 0000020 1 \n $ 6 \nvalue 1 \n * 3 \n $ 0000040 3 \n SET \n $ 4 \nkey 2 \n $ 6 0000060 \nvalue 2 \n $ ( sed 's/$/\r/' < toto.txt ; sleep 1 ) | netcat localhost 6379 +OK +OK 

An extra second gives netcat the opportunity to read the Redis answer.

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

+6
source

All Articles