redis_lock

exception redis_lock.AlreadyAcquired[source]
exception redis_lock.AlreadyStarted[source]
exception redis_lock.InvalidTimeout[source]
class redis_lock.Lock(redis_client, name, expire=None, id=None, auto_renewal=False, strict=True, signal_expire=1000)[source]

A Lock context manager implemented via redis SETNX/BLPOP.

acquire(blocking=True, timeout=None)[source]
Parameters:
  • blocking – Boolean value specifying whether lock should be blocking or not.
  • timeout – An integer value specifying the maximum number of seconds to block.
extend(expire=None)[source]

Extends expiration time of the lock.

Parameters:expire – New expiration time. If None - expire provided during lock initialization will be taken.
locked()[source]

Return true if the lock is acquired.

Checks that lock with same name already exists. This method returns true, even if lock have another id.

release()[source]

Releases the lock, that was acquired with the same object.

Note

If you want to release a lock that you acquired in a different place you have two choices:

  • Use Lock("name", id=id_from_other_place).release()
  • Use Lock("name").reset()
reset()[source]

Forcibly deletes the lock. Use this with care.

exception redis_lock.NotAcquired[source]
exception redis_lock.NotExpirable[source]
exception redis_lock.TimeoutNotUsable[source]
exception redis_lock.TimeoutTooLarge[source]
redis_lock.reset_all(redis_client)[source]

Forcibly deletes all locks if its remains (like a crash reason). Use this with care.

Parameters:redis_client – An instance of StrictRedis.