Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setnx listed as a bulk command, should it be? #6

Open
impact11 opened this issue Aug 30, 2011 · 1 comment
Open

setnx listed as a bulk command, should it be? #6

impact11 opened this issue Aug 30, 2011 · 1 comment

Comments

@impact11
Copy link

According to Redis documentation, setnx takes only two parameters (key and value).
Within redis_protocol.rb, setnx is listed as a bulk command. This seems to cause the send_command() function to append the length of the last argument passed into the function to the command sequence, which causes a Redis error.

Example:
The Ohm library calls

 key[:_lock].setnx(Time.now.to_f + 0.5)

The send_command() function receives a 3-element array:

 argv = [ "setnx", "OhmClassName:132:_lock", "1314673377.348075"]

Because setnx is listed in BULK_COMMAND array at header of redis_protocol.rb, send_command() takes the length of "1314673377.348075" and inserts it into the command list as if it were the value for the command, like so:

 setnx OhmClassName:132:_lock 17 1314673377.348075

This results in an error

:1 -ERR unknown command '1314673377.348075' 

because redis interprets the inserted length (17) as the value, and treats the timestamp that follows as if it were a command.

Changing BULK_COMMAND to make setnx to false seems to rectify this behavior, but this is happening with other Redis commands listed in there that only take two parameters (e.g. 'set', 'sismember', etc). Even for those that take multiple arguments (e.g. sadd) it seems unusual to add the length of the remainder into the command, rather than just appending the remaining arguments.

What is the logic behind the BULK_COMMAND array and the thought behind what commands are listed there, and that block in send_command()? Is there something I am missing?

(Thanks greatly for having made this in the first place, btw!)

@portertech
Copy link

Unified request protocol #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants