can't seem to pipeline mass insertion file vie redis-cli --pipe

1,200 views
Skip to first unread message

Elad Yosifon

unread,
Dec 27, 2013, 9:43:45 PM12/27/13
to redi...@googlegroups.com
no matter what I've tried.. nothing works..
I'm sure that the problem is mine.. but I can't seem to find a solution..


I started with a 1.3GB file..  in the first time I got an error 
ERR Protocol error: expected '$', got '1'

the second time with the same file.. no output at all.. it's like it ignores me..
the third time as well.. etc..etc..

I tried a different tactic..
using a small file..

now I got this error...
All data transferred. Waiting for the last reply...
ERR Protocol error: invalid multibulk length

no matter which example I found on the web..  nothing works..

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"

error:
All data transferred. Waiting for the last reply...
ERR Protocol error: invalid multibulk length

:(

please help..

Matt Stancliff

unread,
Jan 3, 2014, 10:19:12 AM1/3/14
to redi...@googlegroups.com

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

Jan-Erik Rediger

unread,
Jan 3, 2014, 10:24:44 AM1/3/14
to redi...@googlegroups.com
Better to use single-quotes (') if you don't want the shell to touch the
$-prefix characters. Your example only works correctly if the printf is
a shell builtin (and thus has special handling)

Elad Yosifon

unread,
Jan 14, 2014, 4:12:45 PM1/14/14
to redi...@googlegroups.com
thank you..
It was the case... :\
Reply all
Reply to author
Forward
0 new messages