Struct redlock_async::RedLock
source · [−]Expand description
The lock manager.
Implements the necessary functionality to acquire and release locks and handles the Redis connections.
Fields
servers: Vec<Client>List of all Redis clients
Implementations
sourceimpl RedLock
impl RedLock
sourcepub fn new<T: AsRef<str> + IntoConnectionInfo>(uris: Vec<T>) -> RedLock
pub fn new<T: AsRef<str> + IntoConnectionInfo>(uris: Vec<T>) -> RedLock
Create a new lock manager instance, defined by the given Redis connection uris. Quorum is defined to be N/2+1, with N being the number of given Redis instances.
Sample URI: "redis://127.0.0.1:6379"
sourcepub fn get_unique_lock_id(&self) -> Result<Vec<u8>>
pub fn get_unique_lock_id(&self) -> Result<Vec<u8>>
Get 20 random bytes from /dev/urandom.
sourcepub fn set_retry(&mut self, count: u32, delay: u32)
pub fn set_retry(&mut self, count: u32, delay: u32)
Set retry count and retry delay.
Retry count defaults to 3.
Retry delay defaults to 200.
sourcepub async fn unlock(&self, lock: &Lock<'_>)
pub async fn unlock(&self, lock: &Lock<'_>)
Unlock the given lock.
Unlock is best effort. It will simply try to contact all instances and remove the key.
sourcepub async fn lock(
&self,
resource: &[u8],
ttl: usize
) -> Result<Lock<'_>, RedLockError>
pub async fn lock(
&self,
resource: &[u8],
ttl: usize
) -> Result<Lock<'_>, RedLockError>
Acquire the lock for the given resource and the requested TTL.
If it succeeds, a Lock instance is returned,
including the value and the validity time
If it fails. None is returned.
A user should retry after a short wait time.
pub async fn acquire(&self, resource: &[u8], ttl: usize) -> RedLockGuard<'_>
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RedLock
impl Send for RedLock
impl Sync for RedLock
impl Unpin for RedLock
impl UnwindSafe for RedLock
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more