Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis SET fails when value has spaces

I just fired up Redis and am playing around with it. The following works fine:

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 a value can be any string... but not a string with spaces? What's the story here?

like image 683
limp_chimp Avatar asked May 06 '13 04:05

limp_chimp


People also ask

Does Redis set overwrite?

Description. Redis SET command is used to set some string value in redis key. If the key already holds a value, it is overwritten, regardless of its type.

What is difference between HSET and set in Redis?

The only difference between the commands HSET and HMSET is the return value of the commands.

What does HSET do in Redis?

Redis HSET command is used to set field in the hash stored at the key to value. If the key does not exist, a new key holding a hash is created. If the field already exists in the hash, it is overwritten.

What is the recommended size for Redis keys?

The maximum allowed key size is 512 MB.


1 Answers

Maybe it is version related. This here 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 option for the redis-cli instead. Beware that it will add a "\n" at the end of your string:

$ 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"

HTH

bernie

like image 163
Bernie Reiter Avatar answered Oct 12 '22 13:10

Bernie Reiter