rslock - Redlock for Redis in Rust
This is an implementation of Redlock, the distributed locking mechanism built on top of Redis.
Features
- Lock extending
- Async runtime support (async-std and tokio)
- Async redis
Install
[!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.
# It is recommended to pin the version to a minor release, as breaking changes may be introduced between minor versions before 1.0.0.
[!NOTE] The
default
feature of this crate will provideasync-std
. You may optionally use tokio by supplying thetokio-comp
feature flag when installing.
Build
cargo build --release
Usage
use LockManager;
use Duration;
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
Make sure you have Docker running since all tests use testcontainers
. Run tests with:
cargo test --all-features
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.