#distributed-locking #locking #redis #distributed

redlock

Implementation of the distributed locking mechanism built on top of Redis

6 releases (stable)

2.0.0 Apr 6, 2023
1.2.0 Aug 30, 2021
1.1.0 Apr 6, 2021
1.0.0 Jan 15, 2016
0.3.0 Apr 9, 2015

#393 in Concurrency

Download history 139/week @ 2024-12-14 100/week @ 2024-12-21 75/week @ 2024-12-28 263/week @ 2025-01-04 211/week @ 2025-01-11 529/week @ 2025-01-18 438/week @ 2025-01-25 377/week @ 2025-02-01 624/week @ 2025-02-08 245/week @ 2025-02-15 179/week @ 2025-02-22 165/week @ 2025-03-01 229/week @ 2025-03-08 219/week @ 2025-03-15 276/week @ 2025-03-22 108/week @ 2025-03-29

845 downloads per month
Used in 2 crates

BSD-3-Clause

19KB
359 lines

redlock-rs - 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 more or less a port of the Ruby version.

It includes a sample application in main.rs.

Build

cargo build --release

Usage

use redlock::RedLock;

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) {
      Some(l) => { lock = l; break }
      None => ()
    }
  }

  // Critical section

  rl.unlock(&lock);
}

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.

Maintainer

  • From 2014 to June 2021 this crate was owned and maintained by @badboy
  • From June 2021 on this crate is maintained by @aig787

License

BSD. See LICENSE.

Dependencies

~4–11MB
~116K SLoC