pub struct DistributedLockManager { /* private fields */ }Expand description
Thread-safe distributed lock manager (in-memory; production implementations use Redis or etcd).
Implementations§
Source§impl DistributedLockManager
impl DistributedLockManager
pub fn new() -> Self
Sourcepub fn try_acquire(
&self,
resource: &str,
holder: &str,
ttl: Duration,
) -> Option<u64>
pub fn try_acquire( &self, resource: &str, holder: &str, ttl: Duration, ) -> Option<u64>
Try to acquire a lock. Returns the fencing token if acquired, or None if the resource is held by another holder.
Sourcepub fn release(&self, resource: &str, holder: &str) -> bool
pub fn release(&self, resource: &str, holder: &str) -> bool
Release a lock. Only the holder can release.
Sourcepub fn renew(
&self,
resource: &str,
holder: &str,
ttl: Duration,
) -> Option<DateTime<Utc>>
pub fn renew( &self, resource: &str, holder: &str, ttl: Duration, ) -> Option<DateTime<Utc>>
Renew an existing lease. Returns the new expiry time.
Sourcepub fn purge_expired(&self) -> usize
pub fn purge_expired(&self) -> usize
Purge expired leases.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active leases.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DistributedLockManager
impl RefUnwindSafe for DistributedLockManager
impl Send for DistributedLockManager
impl Sync for DistributedLockManager
impl Unpin for DistributedLockManager
impl UnsafeUnpin for DistributedLockManager
impl UnwindSafe for DistributedLockManager
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
Mutably borrows from an owned value. Read more