4 releases (2 breaking)

0.5.1 Nov 24, 2024
0.5.0 Nov 23, 2024
0.4.0 Nov 13, 2024
0.3.0 Oct 24, 2024
0.1.2 Oct 22, 2024

#591 in Database interfaces

Download history 425/week @ 2024-10-19 54/week @ 2024-10-26 1/week @ 2024-11-02 112/week @ 2024-11-09 18/week @ 2024-11-16 280/week @ 2024-11-23 13/week @ 2024-11-30 45/week @ 2024-12-07

365 downloads per month

Apache-2.0

48KB
908 lines

redis-lock

Crates.io docs

Rusty distributed locking backed by Redis.

// Setup.
redis_lock::setup(&client).await?;
// Get lock.
let mut lock = redis_lock::MultiResourceLock::new(client.clone())?;
let resources = vec![String::from("account1"), String::from("account2")];
// Execute a function with the lock.
lock.map_default(&resources, async move { /* .. */ }).await?;

Vs rslock

I would recommend this library over rslock when your application does operations that require exclusive access to multiple resources.

Similar work


lib.rs:

Rusty distributed locking backed by Redis.

Locking a single resource

let connection = Arc::new(Mutex::new(
    client.get_multiplexed_async_connection().await?
));
// Execute a function with the lock.
redis_lock::lock_across(
    &[connection],
    "account1",
    async move { /* .. */ },
    redis_lock::LockAcrossOptions::default()
).await?;

Locking multiple resources

// Setup.
redis_lock::setup(&client).await?;
// Get lock.
let mut lock = redis_lock::MultiResourceLock::new(client.clone())?;
let resources = vec![String::from("account1"), String::from("account2")];
// Execute a function with the lock.
lock.map_default(&resources, async move { /* .. */ }).await?;

Vs rslock

I would recommend this library over rslock when:

  • your application is focussed on async.
  • your application does operations that require exclusive access to multiple resources.

Similar work

Dependencies

~9–19MB
~248K SLoC