Lock(redis, name, timeout=None, sleep=0.1, blocking=True, blocking_timeout=None, thread_local=True)¶
A shared, distributed Lock. Using Redis for locking allows the Lock to be shared across processes and/or machines.
It’s left to the user to resolve deadlock issues and make sure multiple clients play nicely together.
acquire(blocking=None, blocking_timeout=None, token=None)¶
Use Redis to hold a shared, distributed lock named
name. Returns True once the lock is acquired.
blockingis False, always return immediately. If the lock was acquired, return True, otherwise return False.
blocking_timeoutspecifies the maximum number of seconds to wait trying to acquire the lock.
tokenspecifies the token value to be used. If provided, token must be a bytes object or a string that can be encoded to a bytes object with the default encoding. If a token isn’t specified, a UUID will be generated.
Adds more time to an already acquired lock.
additional_timecan be specified as an integer or a float, both representing the number of seconds to add.
replace_ttlif False (the default), add additional_time to the lock’s existing ttl. If True, replace the lock’s ttl with additional_time.
Returns True if this key is locked by any process, otherwise False.
Returns True if this key is locked by this lock, otherwise False.
Resets a TTL of an already acquired lock back to a timeout value.
Releases the already acquired lock