How to tell if SETNX put a value #347
Answered
by
rueian
JeffBNimble
asked this question in
Q&A
-
I'm using the following command to do a "set if not exists", but I'm not sure how to tell if the command set the value or not.
What function do I send to cmd to know the result of the SETNX? |
Beta Was this translation helpful? Give feedback.
Answered by
rueian
Aug 26, 2023
Replies: 1 comment
-
Hi @JeffBNimble, According to this: You can check its return like this: err := c.Do(context.Background(), c.B().Set().Key("someKey").Value(string("someValue")).Nx().Ex(expiration).Build()).Error()
if rueidis.IsRedisNil(err) {
// the SET operation was not performed because the NX condition was not met.
}
if err != nil {
// other error
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JeffBNimble
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @JeffBNimble,
According to this:
You can check its return like this: