-
Notifications
You must be signed in to change notification settings - Fork 2.6k
SETNX with TTL #387
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
Comments
If you're using Redis server 2.6.12 or greater and redis-py 2.7.4 or greater, you can pass additional arguments to the r = redis.StrictRedis(...)
r.set('my-key', 'my-value', nx=True, ex=10) # 10 second expiration, note you can also use `px` for millisecond resolution You could also do this with LUA scripting or with a pipeline+watch command. |
In case others want to set up a lock pattern in Redis, redlock-py offers an implementation of the redlock algorithm that the Redis docs recommend for this purpose. |
you can not use |
@kingname I know this is an old issue, but this seems to be working as expected now :D |
Is it possible to do a atomic SETNX with TTL. I use redis as distributed key value store, and am looking to simulate lock -> update -> release pattern on redis.
Since SETNX doesn't take expiration time, if the thread which obtains lock dies subsequent SETNX's are always false
The text was updated successfully, but these errors were encountered: