On Dec 27, 2013, at 9:43 PM, Elad Yosifon <
elad.y...@gmail.com> wrote:
> this is the most simple one that I can't seem to work..
> echo -n "*3\r\n$3\r\nSET\r\n$3\r\nabc\r\n$1\r\na\r\n" | redis-cli -s /var/run/redis/redis.sock --pipe
> which translates to "SET abc a”
Actually, `echo -n "*3\r\n$3\r\nSET\r\n$3\r\nabc\r\n$1\r\na\r\n”` translates to: "*3\r\n\r\nSET\r\n\r\nabc\r\n\r\na\r\n” — notice how the \r\n is printed directly (they should be printed as actual newlines) *and* all of the dollar sign numbers went away. The shell thinks you’re talking about variables called $3 and $1 and since those don’t exist, they just get replaced with blanks.
We need to use a command that won’t treat $ as variables and will render the newlines as actual control characters. Let’s use `printf` instead of `echo`:
% printf "*3\r\n$3\r\nSET\r\n$3\r\nabc\r\n$1\r\na\r\n"
*3
SET
abc
a
Now with `printf` in place, we can add to Redis with:
% printf "*3\r\n\$3\r\nSET\r\n\$3\r\nabc\r\n\$1\r\na\r\n" | ./redis-cli --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1
-Matt