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

Feature Request: hsetnx variant that also NOPs/fails if the hash ID does not exist #5950

Open
jdavisclark opened this issue Mar 20, 2019 · 0 comments

Comments

@jdavisclark
Copy link

jdavisclark commented Mar 20, 2019

There are a lot of times when I want to set the value of a hash field if-and-only-if the hash field doesn't already exist (covered by HSETNX) and the hash actually exists. This is not currently possible to do with a single command so far as I can tell, and requires either 1) a lua script, 2) multiple non-atomic round trips to redis, or maybe 3) some weird watch/multi/exec combo.

Proposal

Add support for an HESETNX or HSETENX command (not sure on the name) implemented such that it follows the existing behavior of HSETNX, but also returns a failure code if the hash ID does not exist rather than creating the hash.

Potential Issues

There are effectively three states that have to be represented in the response, and I am not sure if any existing commands with a success/fail response return anything more than 0 or 1.

Implementing HESETNX would require that either:

  1. 0 was returned for both failure cases, which I think is too ambiguous
  2. it returns 1 for sucess, 0 for failure in the case that the hash field already existing, and 2 (or something else) in the case that the hash ID did not exist.

Thoughts?

@jdavisclark jdavisclark changed the title Feature Request: hsetnx variant that also NOPs out if the hash ID does not exist Feature Request: hsetnx variant that also NOPs/fails if the hash ID does not exist Mar 20, 2019
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

1 participant