You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
0 was returned for both failure cases, which I think is too ambiguous
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?
The text was updated successfully, but these errors were encountered:
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
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
orHSETENX
command (not sure on the name) implemented such that it follows the existing behavior ofHSETNX
, 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
or1
.Implementing
HESETNX
would require that either:0
was returned for both failure cases, which I think is too ambiguous1
for sucess,0
for failure in the case that the hash field already existing, and2
(or something else) in the case that the hash ID did not exist.Thoughts?
The text was updated successfully, but these errors were encountered: