Comment on A proposal for more reliable locks using RedisComments−ThePhysicist12yI wrote a very similar, Redis-based lock in Python a while ago, here it is:https://gist.github.com/adewes/6103220It uses Redis pipelines and watchers to make sure that no race conditions between two processes requiring the same lock occur, and uses "expire" keys to avoid deadlocks.−klibertp12yI prefer Lua-scripting based approach: https://github.com/bbangert/retools/blob/master/retools/lock..., but I had to implement something similar to your code to support older Redis versions.−thezilch12yYou should just use redis-py's Lock (https://github.com/andymccurdy/redis-py/blob/master/redis/cl...)
Comments
I wrote a very similar, Redis-based lock in Python a while ago, here it is:
https://gist.github.com/adewes/6103220
It uses Redis pipelines and watchers to make sure that no race conditions between two processes requiring the same lock occur, and uses "expire" keys to avoid deadlocks.
I prefer Lua-scripting based approach: https://github.com/bbangert/retools/blob/master/retools/lock..., but I had to implement something similar to your code to support older Redis versions.
You should just use redis-py's Lock (https://github.com/andymccurdy/redis-py/blob/master/redis/cl...)