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

Make setIfNotExists atomic? #156

Closed
jgdodson opened this issue Mar 28, 2018 · 3 comments
Closed

Make setIfNotExists atomic? #156

jgdodson opened this issue Mar 28, 2018 · 3 comments
Labels
Milestone

Comments

@jgdodson
Copy link

jgdodson commented Mar 28, 2018

I was looking over the redis docs and saw that since redis 2.6.12, it has been possible to SET with both an existence condition (if-not-exists or only-if-exists) and and expiry time (with millisecond resolution). Would this not allow the implementation of setIfNotExists to be made atomic?

@KarelCemus
Copy link
Owner

You mean changing this implementation to SET instead of SETNX?

@jgdodson
Copy link
Author

jgdodson commented Mar 28, 2018

Yes to using SET (with the NX option) instead of SETNX (which the docs warn may be deprecated one day). However, the real optimization would be to also use the EX option of SET instead of the expire() command. This would allow this implementation to be changed so that it makes only one call to the connector (hence atomic). The connector method would need a new parameter for the expire duration.

[Edit]

As a side note, since 2.6.12, all usages of SETNX, SETPX, SETEX can be streamlined by using SET with the new options discussed here.

@jgdodson
Copy link
Author

Awesome! Thanks for working on this.

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

No branches or pull requests

2 participants