https://github.com/magiclen/rlock
An easy-to-use Redis-backed lock library providing both async and sync Mutex, RwLock, and others.
https://github.com/magiclen/rlock
distributed mutex redis rust rwlock
Last synced: 5 months ago
JSON representation
An easy-to-use Redis-backed lock library providing both async and sync Mutex, RwLock, and others.
- Host: GitHub
- URL: https://github.com/magiclen/rlock
- Owner: magiclen
- Created: 2025-09-25T07:27:27.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-09-25T07:52:59.000Z (9 months ago)
- Last Synced: 2025-09-25T09:28:25.685Z (9 months ago)
- Topics: distributed, mutex, redis, rust, rwlock
- Language: Rust
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
RLock (Redis Lock)
====================
[](https://github.com/magiclen/rlock/actions/workflows/ci.yml)
It is an easy-to-use Redis-backed lock library providing both async and sync Mutex, RwLock, and others.
## Examples
```rust
use tokio::task::JoinSet;
use rlock::async_lock::RLock;
static mut COUNTER: u32 = 0;
#[tokio::main]
async fn main() {
let rlock = RLock::new("redis://127.0.0.1:6379/0").await.unwrap();
async fn counter_increase(rlock: RLock) {
let lock = rlock.acquire_mutex("lock").await.unwrap();
// ----- critical section -----
unsafe { COUNTER += 1 };
// ----------------------------
drop(lock);
}
let mut tasks = JoinSet::new();
for _ in 0..1000 {
tasks.spawn(counter_increase(rlock.clone()));
}
tasks.join_all().await;
assert_eq!(1000, unsafe { COUNTER });
rlock.shutdown().await;
}
```
## Roadmap / TODO
- [x] Asynchronous mutex lock
- [ ] Synchronous mutex lock
- [ ] Asynchronous read-write lock
- [ ] Synchronous read-write lock
## Crates.io
https://crates.io/crates/rlock
## Documentation
https://docs.rs/rlock
## License
[MIT](LICENSE)