Crates.io | redsync |
lib.rs | redsync |
version | 1.0.1 |
source | src |
created_at | 2021-03-01 07:03:01.882074 |
updated_at | 2023-04-18 20:01:59.701222 |
description | A Rust implementation of Redlock for distributed locks with Redis |
homepage | https://github.com/jace-ys/redsync |
repository | https://github.com/jace-ys/redsync |
max_upload_size | |
id | 362098 |
size | 37,150 |
A Rust implementation of Redlock for distributed locks with Redis.
Add the following line to your Cargo.toml file:
[dependencies]
redsync = "1.0.1"
use std::error::Error;
use std::time::Duration;
use redsync::{RedisInstance, Redsync};
fn main() -> Result<(), Box<dyn Error>> {
let dlm = Redsync::new(vec![
RedisInstance::new("redis://127.0.0.1:6389")?,
RedisInstance::new("redis://127.0.0.1:6399")?,
RedisInstance::new("redis://127.0.0.1:6379")?,
]);
let lock = dlm.lock("resource", Duration::from_secs(1))?;
dlm.unlock(&lock)?;
Ok(())
}
For more examples, see examples.