coolexp / redis

Automatically exported from code.google.com/p/redis
0 stars 0 forks source link

Numeric error codes break the protocol #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Consider this

-> RPUSH l 3
-> aaa
<- +OK
-> SET i -42
<- +OK
-> GET l
<- -42
<- GET against key not holding a string value
-> GET i
<- -42

How can you differentiate the error message in the client returned by "GET
l" from the value returned by "GET b"?

You cannot inspect the next line, as in the case of "GET b" the socket
would block as there's nothing more to read.

I think you should change error messages so that they have always a first
line with

-ERR

then if you still want to return an error code, you can stuff that in the
second line, before the error message. It will be trivial to split the
second line and try to cast the first token to int to check if it's an
error code.

Then write in the docs that storing '-ERR\r\nSome stuff here\r\n' will
never return that as a value but as an error message.

Original issue reported on code.google.com by ludovico...@siassb.eu on 2 Mar 2009 at 9:40

GoogleCodeExporter commented 8 years ago
fix to the above script

-> SET i 3
-> -42

I wrote in pseudo-redis commands :)

Original comment by ludovico...@siassb.eu on 2 Mar 2009 at 9:45

GoogleCodeExporter commented 8 years ago
Ludo only the errors will have a negative number of bytes as count.

SET i -42

is actually setting an empty string. This should issue an error, actually.
To set i at -42 you should issue:

SET i 3
-42

then GET i will produce:
3
-42

Did i missed the point?

Original comment by anti...@gmail.com on 2 Mar 2009 at 9:46

GoogleCodeExporter commented 8 years ago
btw this is what I get:

set i -42
-ERR invalid bulk write count

Original comment by anti...@gmail.com on 2 Mar 2009 at 9:47

GoogleCodeExporter commented 8 years ago
uhm

right :)

Original comment by ludovico...@siassb.eu on 2 Mar 2009 at 9:48

GoogleCodeExporter commented 8 years ago
Coffee has not yet kicked in, sorry :)

Original comment by ludovico...@siassb.eu on 2 Mar 2009 at 9:49

GoogleCodeExporter commented 8 years ago
no prob! Btw I'll prefix with -ERR anyway every bulk write in order to make 
this a
client implementation detail, or read the count, if negative read the error 
line,
conitnue. Otherwise just use the same codepath of bulk read but raise an error.

Original comment by anti...@gmail.com on 2 Mar 2009 at 9:57