ionelmc/python-redis-lock — pull request #11 by ionelmc (2014-12-26 20:01:56+00:00)
Title: Allow users to define which data they want to associate with the lock.

This is useful in cases where the application needs to identify the
lock owner (find out who currently owns the lock).

Example:

this_instance = 'string-identifying-this-instance-uniquely'
lock = cache.lock(lock_name, expire=lock_ttl, id=this_instance)

lock_value = lock.get_owner_id(lock_name)

if lock_value != None: # Lock already acquired?
if lock_value == this_instance: # By me?
logger.info('The lock is already mine')
# ...
else:
logger.info('The lock belongs to someone else')
# ...
else: # Lock not yet acquired?
if lock.acquire(blocking=False): # Try to acquire it!
logger.info('I acquired the lock')
# ...
else:
logger.info('Someone else got the lock')
# ...