def __init__(self, key):
self.key = "lock.%s" % key
value = getClient().add(self.key, "1", 60000)
if value == True:
def __exit__(self, exc_type, exc_val, exc_tb):
Using the lock is as simple as doing:
The advantage over Sylvain's Java version is that the locking code is reusable, thanks to the use of a Python context manager.