pub struct MultiResourceLock { /* private fields */ }
sync
only.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
impl MultiResourceLock
Sourcepub fn new(client: &Client) -> RedisResult<Self>
pub fn new(client: &Client) -> RedisResult<Self>
Sourcepub fn acquire_default(
&mut self,
resources: &[String],
) -> RedisResult<Option<String>>
pub fn acquire_default( &mut self, resources: &[String], ) -> RedisResult<Option<String>>
Calls MultiResourceLock::acquire
with DEFAULT_EXPIRATION
, DEFAULT_TIMEOUT
and DEFAULT_SLEEP
.
§Errors
When MultiResourceLock::acquire
errors.
Sourcepub fn acquire(
&mut self,
resources: &[String],
expiration: Duration,
timeout: Duration,
sleep: Duration,
) -> RedisResult<Option<String>>
pub 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.
Sourcepub fn try_acquire_default(
&mut self,
resources: &[String],
) -> RedisResult<Option<String>>
pub fn try_acquire_default( &mut self, resources: &[String], ) -> RedisResult<Option<String>>
Calls MultiResourceLock::try_acquire
with DEFAULT_EXPIRATION
.
§Errors
When MultiResourceLock::try_acquire
errors.
Sourcepub fn try_acquire(
&mut self,
resources: &[String],
expiration: Duration,
) -> RedisResult<Option<String>>
pub 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.
Sourcepub fn release(&mut self, lock_id: &str) -> RedisResult<usize>
pub 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.
Sourcepub fn try_lock_default(
&mut self,
resources: &[String],
) -> RedisResult<Option<MultiResourceGuard<'_>>>
pub fn try_lock_default( &mut self, resources: &[String], ) -> RedisResult<Option<MultiResourceGuard<'_>>>
Calls MultiResourceLock::try_lock
with DEFAULT_EXPIRATION
.
§Errors
When MultiResourceLock::try_lock
errors.
Sourcepub fn try_lock(
&mut self,
resources: &[String],
expiration: Duration,
) -> RedisResult<Option<MultiResourceGuard<'_>>>
pub 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.
Sourcepub fn lock_default(
&mut self,
resources: &[String],
) -> RedisResult<Option<MultiResourceGuard<'_>>>
pub fn lock_default( &mut self, resources: &[String], ) -> RedisResult<Option<MultiResourceGuard<'_>>>
Calls MultiResourceLock::lock
with DEFAULT_EXPIRATION
, DEFAULT_TIMEOUT
and DEFAULT_SLEEP
.
§Errors
When MultiResourceLock::lock
errors.
Sourcepub fn lock(
&mut self,
resources: &[String],
expiration: Duration,
timeout: Duration,
sleep: Duration,
) -> RedisResult<Option<MultiResourceGuard<'_>>>
pub 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§
Auto Trait Implementations§
impl Freeze for MultiResourceLock
impl !RefUnwindSafe for MultiResourceLock
impl Send for MultiResourceLock
impl Sync for MultiResourceLock
impl Unpin for MultiResourceLock
impl !UnwindSafe for MultiResourceLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more