elock

Crates.ioelock
lib.rselock
version0.1.1
created_at2025-07-09 09:48:30.374029+00
updated_at2025-07-10 02:50:04.658122+00
descriptionA lightweight distributed lock implementation built on top of etcd using leases and watch
homepage
repositoryhttps://github.com/nautilus-ops/elock
max_upload_size
id1744589
size50,821
CeerDecy (CeerDecy)

documentation

README

Elock

License Rust Kubernetes etcd

A lightweight distributed lock implementation built on top of etcd using leases and watch

Install

cargo add elock

Example

You can new a LockManager to manage etcd locks.


use elock::LockManager;
use std::time::Duration;

#[tokio::main]
async fn main() {
    let mut manager = LockManager::new("127.0.0.1:2379")
        .with_tls("/etc/etcd/ssl/etcd-ca.pem", "/etc/etcd/ssl/etcd-client.pem", "/etc/etcd/ssl/etcd-client-key.pem")
        .init()
        .await;
    let mut locker = manager.create_lock("/test/lock").await;
    
    // Duration sets the timeout for acquiring a lock, similar to context.WithTimeout in Golang.
    locker.lock(Duration::from_secs(30)).await.unwrap();

    // Do something

    locker.unlock().await.unwrap();
    
    tracing::info!("Unlock successful");
}

Commit count: 0

cargo fmt