redis_lock

Struct MultiResourceLock

source
pub struct MultiResourceLock { /* private fields */ }
Expand description

A distributed mutual exclusion lock backed by Redis.

Supports exclusion based on multiple resources and partial overlaps.

E.g. a lock on resources ["a", "b"] will block a lock on ["a"] or ["b", "c"].

Implementations§

source§

impl MultiResourceLock

source

pub fn new(client: Client) -> RedisResult<Self>

Create a new instance of the lock.

§Errors

When Client::get_connection errors.

source

pub async fn acquire_default( &mut self, resources: &[String], ) -> RedisResult<Option<String>>

source

pub async fn acquire( &mut self, resources: &[String], expiration: Duration, timeout: Duration, sleep: Duration, ) -> RedisResult<Option<String>>

Attempts to acquire the lock blocking until the lock can be acquired.

Blocks up to timeout duration making attempts every sleep duration.

Returns None when it times out.

§Errors

When MultiResourceLock::try_acquire errors.

source

pub async fn try_acquire_default( &mut self, resources: &[String], ) -> RedisResult<Option<String>>

source

pub async fn try_acquire( &mut self, resources: &[String], expiration: Duration, ) -> RedisResult<Option<String>>

Attempts to acquire the lock returning immediately if it cannot be immediately acquired.

§Errors
  • When the acquire_lock function is missing from the Redis instance.
source

pub async fn release(&mut self, lock_id: &str) -> RedisResult<usize>

Releases a held lock.

§Errors
  • When the release_lock function is missing from the Redis instance.
  • When lock_id does not refer to a held lock.
source

pub async fn try_lock_default( &mut self, resources: &[String], ) -> RedisResult<Option<MultiResourceGuard<'_>>>

source

pub async fn try_lock( &mut self, resources: &[String], expiration: Duration, ) -> RedisResult<Option<MultiResourceGuard<'_>>>

Attempts to acquire the lock returning immediately if it cannot be immediately acquired.

Wraps the result in a guard that releases the lock when dropped.

§Errors

When MultiResourceLock::try_acquire errors.

source

pub async fn lock_default( &mut self, resources: &[String], ) -> RedisResult<Option<MultiResourceGuard<'_>>>

source

pub async fn lock( &mut self, resources: &[String], expiration: Duration, timeout: Duration, sleep: Duration, ) -> RedisResult<Option<MultiResourceGuard<'_>>>

Attempts to acquire the lock blocking until the lock can be acquired.

Blocks up to timeout duration making attempts every sleep duration.

Returns None when it times out.

Wraps the result in a guard that releases the lock when dropped.

§Errors

When MultiResourceLock::acquire errors.

Trait Implementations§

source§

impl Debug for MultiResourceLock

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.