pub struct InMemoryLockBackend { /* private fields */ }Expand description
In-memory distributed lock backend.
This backend stores locks in a HashMap guarded by a tokio::sync::RwLock.
It is suitable for single-process deployments or testing. For true distributed
locking across multiple processes/hosts, use RedisLockBackend or DbLockBackend.
Expired locks are lazily cleaned up on each operation.
§Example
use celers_beat::lock::InMemoryLockBackend;
use celers_core::lock::DistributedLockBackend;
let backend = InMemoryLockBackend::new();
let acquired = backend.try_acquire("my_task", "scheduler-1", 300).await.unwrap();
assert!(acquired);Implementations§
Source§impl InMemoryLockBackend
impl InMemoryLockBackend
Sourcepub async fn active_lock_count(&self) -> usize
pub async fn active_lock_count(&self) -> usize
Get the number of currently held (non-expired) locks
Trait Implementations§
Source§impl Clone for InMemoryLockBackend
impl Clone for InMemoryLockBackend
Source§impl Debug for InMemoryLockBackend
impl Debug for InMemoryLockBackend
Source§impl Default for InMemoryLockBackend
impl Default for InMemoryLockBackend
Source§impl DistributedLockBackend for InMemoryLockBackend
impl DistributedLockBackend for InMemoryLockBackend
Source§fn try_acquire<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn try_acquire<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Try to acquire a lock. Returns
Ok(true) if acquired successfully. Read moreSource§fn release<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn release<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Release a lock. Returns
Ok(true) if released (was owned by this owner). Read moreSource§fn renew<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn renew<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: &'life2 str,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Renew/extend a lock’s TTL. Returns
Ok(true) if renewed. Read moreSource§fn is_locked<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn is_locked<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if a lock is currently held by anyone. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for InMemoryLockBackend
impl !UnwindSafe for InMemoryLockBackend
impl Freeze for InMemoryLockBackend
impl Send for InMemoryLockBackend
impl Sync for InMemoryLockBackend
impl Unpin for InMemoryLockBackend
impl UnsafeUnpin for InMemoryLockBackend
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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