rslock - Redlock for Redis in Rust
This is an implementation of Redlock, the distributed locking mechanism built on top of Redis.
[!WARNING] Before release
1.0.0
, this crate will have breaking changes between minor versions. You can upgrade to patch versions without worrying about breaking changes.
Features
- Lock extending
- Async runtime support (async-std and tokio)
- Async redis
Install
[!NOTE] The
default
feature of this crate will provide async-std. You may optionally use tokio by supplying thetokio-comp
feature flag when installing, but tokio has limitations that will not grant access to some parts of the API (read more here).
Build
cargo build --release
Usage
use Duration;
use LockManager;
async
Extending Locks
Extending a lock effectively renews its duration instead of adding extra time to it. For instance, if a 1000ms lock is extended by 1000ms after 500ms pass, it will only last for a total of 1500ms, not 2000ms. This approach is consistent with the Node.js Redlock implementation. See the extend script.
Tests
Run tests with:
cargo test
Examples
Start the redis servers mentioned in the example code:
Run the examples:
Stop the redis servers:
Contribute
If you find bugs or want to help otherwise, please open an issue.
License
BSD. See LICENSE.