#distributed #locking #redis #redlock

redlock-async

Implementation of the distributed locking mechanism built on top of Async Redis

3 releases

0.0.3 Sep 9, 2022
0.0.2 Sep 9, 2022
0.0.1 Sep 9, 2022

#1119 in Database interfaces

Download history 49/week @ 2023-02-10 55/week @ 2023-02-17 258/week @ 2023-02-24 178/week @ 2023-03-03 122/week @ 2023-03-10 70/week @ 2023-03-17 154/week @ 2023-03-24 89/week @ 2023-03-31 52/week @ 2023-04-07 66/week @ 2023-04-14 146/week @ 2023-04-21 70/week @ 2023-04-28 167/week @ 2023-05-05 85/week @ 2023-05-12 54/week @ 2023-05-19 72/week @ 2023-05-26

398 downloads per month

BSD-3-Clause

16KB
328 lines

redlock-async-rs - Async Distributed locks with Redis

GitHub Workflow Status Crates.io

This is an implementation of Redlock, the distributed locking mechanism built on top of Redis.

It is a fork of existing redlock-rs with async built on top of it.

Build

cargo build --release

Usage

use redlock::RedLock;

#[tokio::main]
fn main() {
  let rl = RedLock::new(vec!["redis://127.0.0.1:6380/", "redis://127.0.0.1:6381/", "redis://127.0.0.1:6382/"]);

  let lock;
  loop {
    match rl.lock("mutex".as_bytes(), 1000).await {
      Ok(l) => { lock = l; break }
      Err(_) => ()
    }
  }

  // Critical section
  rl.unlock(&lock).await;
}

Tests

Run tests with:

cargo test

Run sample application with:

cargo run --release

Contribute

If you find bugs or want to help otherwise, please open an issue.

License

BSD. See LICENSE.

Dependencies

~7–14MB
~271K SLoC