1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Distributed locks for Rust with multiple backend support.
//!
//! This crate provides distributed synchronization primitives (mutex locks,
//! reader-writer locks, semaphores) that work across processes and machines.
//! Multiple backend implementations are available: PostgreSQL, Redis, and file system.
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use distributed_lock::*;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a provider (example: file backend)
//! let provider = FileLockProvider::builder()
//! .build("/tmp/locks")?;
//!
//! // Create a lock by name
//! let lock = provider.create_lock("my-resource");
//!
//! // Acquire the lock with a timeout
//! let handle = lock.acquire(Some(Duration::from_secs(5))).await?;
//!
//! // Critical section - we have exclusive access
//! println!("Doing critical work...");
//!
//! // Release the lock (also happens automatically on drop)
//! handle.release().await?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Backends
//!
//! ## File System Backend
//!
//! Uses OS-level file locking. Simple and requires no external services.
//!
//! ```rust,no_run
//! use distributed_lock::FileLockProvider;
//!
//! let provider = FileLockProvider::builder()
//! .build("/tmp/locks")?;
//! ```
//!
//! ## PostgreSQL Backend
//!
//! Uses PostgreSQL advisory locks. Production-ready with connection pooling.
//!
//! ```rust,no_run
//! use distributed_lock::PostgresLockProvider;
//!
//! let provider = PostgresLockProvider::builder()
//! .connection_string("postgresql://user:pass@localhost/db")
//! .build()
//! .await?;
//! ```
//!
//! ## Redis Backend
//!
//! Uses Redis with RedLock algorithm for multi-server deployments. Supports
//! semaphores and automatic lease extension.
//!
//! ```rust,no_run
//! use distributed_lock::RedisLockProvider;
//!
//! let provider = RedisLockProvider::builder()
//! .add_server("redis://localhost:6379")
//! .build()
//! .await?;
//! ```
//!
//! # Features
//!
//! - **Exclusive Locks**: Mutual exclusion across processes
//! - **Reader-Writer Locks**: Multiple readers or single writer
//! - **Semaphores**: Limit concurrent access to N processes
//! - **Async/Await**: Full async support with tokio
//! - **Backend Agnostic**: Swap backends without changing application code
//! - **Handle Loss Detection**: Detect when locks are lost due to connection issues
//!
//! # Crate Organization
//!
//! This is a meta-crate that re-exports types from:
//! - `distributed-lock-core`: Core traits and types
//! - `distributed-lock-file`: File system backend
//! - `distributed-lock-postgres`: PostgreSQL backend
//! - `distributed-lock-redis`: Redis backend
//!
//! For fine-grained control, you can depend on individual crates instead.
// Re-export core types and traits
pub use *;
// Re-export file backend
pub use *;
// Re-export postgres backend
pub use *;
// Re-export redis backend
pub use *;