Skip to content

How to tell if SETNX put a value #347

Answered by rueian
JeffBNimble asked this question in Q&A
Discussion options

You must be logged in to vote

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
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JeffBNimble
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants