Skip to main content

DistributedLock

Trait DistributedLock 

Source
pub trait DistributedLock: Send + Sync {
    // Required methods
    fn try_acquire<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        ttl_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<bool, ClusterError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn release<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn extend<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        extra_ttl_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Interface for distributed locking mechanisms. Ensures that scheduled tasks or singleton operations run exactly once across the cluster.

Required Methods§

Source

fn try_acquire<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Attempts to acquire a distributed lock.

§Arguments
  • key - The unique identifier for the lock.
  • ttl_ms - Time-to-live in milliseconds before the lock automatically expires.
§Returns
  • Ok(true) if the lock was successfully acquired.
  • Ok(false) if the lock is currently held by another node.
  • Err if a cluster or connection error occurred.
Source

fn release<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Releases a previously acquired distributed lock.

§Arguments
  • key - The unique identifier for the lock.
Source

fn extend<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, extra_ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Extends the expiration time of an actively held lock.

§Arguments
  • key - The unique identifier for the lock.
  • extra_ttl_ms - Additional time-to-live to add to the lock.

Implementors§