docs/integrations/prefect-redis/api-ref/prefect_redis-locking.mdx
prefect_redis.lockingRedisLockManager <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L11" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>A lock manager that uses Redis as a backend.
Attributes:
host: The host of the Redis serverport: The port the Redis server is running ondb: The database to write to and read fromusername: The username to use when connecting to the Redis serverpassword: The password to use when connecting to the Redis serverssl: Whether to use SSL when connecting to the Redis serverclient: The Redis client used to communicate with the Redis serverasync_client: The asynchronous Redis client used to communicate with the Redis serverMethods:
aacquire_lock <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L142" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>aacquire_lock(self, key: str, holder: str, acquire_timeout: Optional[float] = None, hold_timeout: Optional[float] = None) -> bool
Acquires a lock asynchronously.
Args:
key: Unique identifier for the transaction record.holder: Unique identifier for the holder of the lock. Must match the
holder provided when acquiring the lock.acquire_timeout: Maximum time to wait for the lock to be acquired.hold_timeout: Maximum time to hold the lock.Returns:
acquire_lock <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>acquire_lock(self, key: str, holder: str, acquire_timeout: Optional[float] = None, hold_timeout: Optional[float] = None) -> bool
Acquires a lock synchronously.
Args:
key: Unique identifier for the transaction record.holder: Unique identifier for the holder of the lock.acquire_timeout: Maximum time to wait for the lock to be acquired.hold_timeout: Maximum time to hold the lock.Returns:
await_for_lock <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L218" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>await_for_lock(self, key: str, timeout: Optional[float] = None) -> bool
is_lock_holder <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L231" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>is_lock_holder(self, key: str, holder: str) -> bool
is_locked <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L226" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>is_locked(self, key: str) -> bool
release_lock <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L177" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>release_lock(self, key: str, holder: str) -> None
Releases the lock on the corresponding transaction record.
Handles the case where a lock might have been released during a task retry If the lock doesn't exist in Redis at all, this method will succeed even if the holder ID doesn't match the original holder.
Args:
key: Unique identifier for the transaction record.holder: Unique identifier for the holder of the lock. Must match the
holder provided when acquiring the lock.Raises:
ValueError: If the lock is held by a different holder.wait_for_lock <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/locking.py#L210" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>wait_for_lock(self, key: str, timeout: Optional[float] = None) -> bool