Redis SET fails when value has spaces

I just released Redis and I play with it. The following works great:

SET billybob "hello" +OK 

However, the following fails:

 SET billybob "hey how are you" -ERR syntax error 

I thought SET worked for any key / value, and presumably the value could be any string ... but not a string with spaces? What is the story here?

+4
source share
3 answers

Perhaps this is the version. It works:

 $ redis-cli --version redis-cli 2.8.3 $ redis-cli SET billybob "hey how are you" OK $ redis-cli GET billybob "hey how are you" 

@ jm3 Use the -x command line command for redis-cli instead. Remember that it will add "\ n" to the end of the line:

 $ echo "hey how are you" hey how are you $ echo "hey how are you" | redis-cli --pipe SET billybob All data transferred. Waiting for the last reply... ERR unknown command 'hey' Last reply received from server. errors: 1, replies: 1 $ echo "hey how are you" | redis-cli -x SET billybob OK $ redis-cli GET billybob "hey how are you\n" 

NTN

Bernie

+1
source

It seems that you are executing commands on telnet. In principle, redis implements text commands based on a low-level text protocol; a request / response can contain several text strings with a prefix of special characters, such as $ *, or characters with a prefix of its length.

And for convenience, redis also supports built-in commands :

For this reason, Redis also accepts commands in a special way that is designed for people, and is called the command line format. (see here )

The first command you entered is a built-in command , it works. The second has spaces, not a built-in command , and then is broken.

So you can use the inline command to send the set command with spaces:

 *3 $3 set $8 billybob $15 hey how are you +OK 

Reidis Protocol Documentation

0
source

You can try FastoRedis or FastoNoSQL which is based on hiredis : enter image description here

0
source

Source: https://habr.com/ru/post/1479296/


All Articles