nestrs-locks
Lease locks for nestrs — NestJS @nestjs/locks analogue.
Use for single-runner cron, leader election–style critical sections, and any work that must not overlap across process replicas. Locks expire after a TTL so a crashed holder cannot block forever.
Install
[]
= "1.7.1"
Or via the umbrella:
= { = "1.7.1", = ["locks"] }
# Redis backend (optional):
# nestrs-locks = { version = "1.7.1", features = ["cache-redis"] }
Register
use ;
;
Acquire
use LocksService;
use Arc;
async
async
async
try_acquire returns None if another holder owns the name. with_lock runs the closure only when the lock is obtained.
Surface
LocksModule/LocksOptions/LocksServiceLockGuard(RAII release)InMemoryLockStore/SharedInMemoryLockStoreRedisLockStore(cache-redis)LockStoretrait for custom backends
Docs
- Guide: Locks
- rustdoc: https://docs.rs/nestrs-locks/1.7.1
- Lab:
cargo run -p lab --bin lab9_nestjs12
License
MIT OR Apache-2.0.