I've read mass-insert provided at redis.io, but it really confused me. I tried to make a file then use "cat data.txt | redis-cli --pipe" to insert:
SET Key0 Value0
SET Key1 Value1
SET Key2 Value3
Then I got this:
All data transferred. Waiting for the last reply...
ERR wrong number of arguments for 'set' command
ERR unknown command '$4'
ERR wrong number of arguments for 'echo' command
ERR unknown command '$20'
I also tried
*3<cr><lf>
$3<cr><lf>
SET<cr><lf>
$3<cr><lf>
key<cr><lf>
$5<cr><lf>
value<cr><lf>
Then I got this: ERR Protocol error: invalid multi bulk length
It really make me confused. Can anyone give me a simple example? Thank you very much.
I was able to work with the
SET Key0 Value0
form.Please have a look at https://stackoverflow.com/a/30511742/2613942
The reply is about the
LPUSH
command. It also works fine withSET
.To summarize, double-quote the parameters
Change the format of the file from unix to windows with
unix2dos
:Then import using
cat myfile.txt | src/redis-cli --pipe
That worked for me.
Here it is:
Your problem probably comes from the cr+lf separators. You can use the hexdump -C command to check this point:
Also, you may want to check your target is a recent Redis instance and not a pre-1-2 version (which does not support the "unified protocol").
Note: the above lines works fine with zsh. If you use bash, you need to add a $ before the quote to trigger ANSI-C quoting:
You can do it like this:
I hope that helps you!