Struct RedLock

Source
pub struct RedLock {
    pub servers: Vec<Client>,
    /* private fields */
}
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§

Source§

impl RedLock

Source

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"

Source

pub fn with_client(server: Client) -> RedLock

Source

pub fn with_clients(servers: Vec<Client>) -> RedLock

Create a new lock manager instance, defined by the given Redis client instance. Quorum is defined to be N/2+1, with N being the number of given client instances.

Source

pub fn get_unique_lock_id(&self) -> Result<Vec<u8>>

Get 20 random bytes from /dev/urandom.

Source

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.

Source

pub fn lock( &self, resource: &[u8], ttl: usize, ) -> Result<Option<Lock<'_>>, RedisError>

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

Err(RedisError) is returned on any Redis error, None is returned if the lock could not be acquired and the user should retry

Source

pub fn acquire( &self, resource: &[u8], ttl: usize, ) -> Result<RedLockGuard<'_>, RedisError>

Source

pub 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.

Trait Implementations§

Source§

impl Clone for RedLock

Source§

fn clone(&self) -> RedLock

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RedLock

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V