{"id":20394269,"url":"https://github.com/hexcowboy/rslock","last_synced_at":"2025-04-06T07:11:01.499Z","repository":{"id":60180294,"uuid":"535397105","full_name":"hexcowboy/rslock","owner":"hexcowboy","description":"Distributed locks in async Redis with support for lock extending (Redlock implementation)","archived":false,"fork":false,"pushed_at":"2025-03-28T19:47:48.000Z","size":134,"stargazers_count":76,"open_issues_count":4,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T04:07:35.311Z","etag":null,"topics":["distributed-lock","dls","redis","redlock","redlock-redis","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rsecob/redlock-async-rs","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hexcowboy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["hexcowboy"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2022-09-11T19:00:56.000Z","updated_at":"2025-03-30T21:44:25.000Z","dependencies_parsed_at":"2024-06-05T18:50:32.532Z","dependency_job_id":"893e309c-1ac8-4e0d-882f-64821c867d72","html_url":"https://github.com/hexcowboy/rslock","commit_stats":{"total_commits":70,"total_committers":13,"mean_commits":5.384615384615385,"dds":0.7142857142857143,"last_synced_commit":"9b8acbbbade70d36e6589d3faf42aa8d0a421930"},"previous_names":["hexcowboy/redlock-async-rs"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexcowboy%2Frslock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexcowboy%2Frslock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexcowboy%2Frslock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexcowboy%2Frslock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hexcowboy","download_url":"https://codeload.github.com/hexcowboy/rslock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445669,"owners_count":20939958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-lock","dls","redis","redlock","redlock-redis","rust"],"created_at":"2024-11-15T03:52:25.876Z","updated_at":"2025-04-06T07:11:01.455Z","avatar_url":"https://github.com/hexcowboy.png","language":"Rust","funding_links":["https://github.com/sponsors/hexcowboy"],"categories":[],"sub_categories":[],"readme":"# rslock - Redlock for Redis in Rust\n\n[![Crates.io](https://img.shields.io/crates/v/rslock)][crates.io]\n[![Docs badge]][docs.rs]\n\nThis is an implementation of Redlock, the [distributed locking mechanism](http://redis.io/topics/distlock) built on top of Redis.\n\n\u003e [!WARNING]\n\u003e Before release `1.0.0`, this crate will have breaking changes between minor versions. You can upgrade to patch versions without worrying about breaking changes.\n\n## Features\n\n- Lock extending\n- Async runtime support (async-std and tokio)\n- Async redis\n\n## Install\n\n```bash\ncargo add rslock\n```\n\n\u003e [!NOTE]\n\u003e The `default` feature of this crate will provide `async-std`. You may optionally use tokio by supplying the `tokio-comp` feature flag when installing.\n\n## Build\n\n```\ncargo build --release\n```\n\n## Usage\n\n```rust\nuse rslock::LockManager;\nuse std::time::Duration;\n\n#[tokio::main]\nasync fn main() {\n    // Define Redis URIs\n    let uris = vec![\n        \"redis://127.0.0.1:6380/\",\n        \"redis://127.0.0.1:6381/\",\n        \"redis://127.0.0.1:6382/\",\n    ];\n\n    // Initialize the LockManager using `new`\n    let rl = LockManager::new(uris);\n\n    // Acquire a lock\n    let lock = loop {\n        if let Ok(lock) = rl\n            .lock(\"mutex\".as_bytes(), Duration::from_millis(1000))\n            .await\n        {\n            break lock;\n        }\n    };\n\n    println!(\"Lock acquired!\");\n\n    // Extend the lock\n    if rl.extend(\u0026lock, Duration::from_millis(1000)).await.is_ok() {\n        println!(\"Lock extended!\");\n    } else {\n        println!(\"Failed to extend the lock.\");\n    }\n\n    // Unlock the lock\n    rl.unlock(\u0026lock).await;\n    println!(\"Lock released!\");\n}\n```\n\n## Extending Locks\n\nExtending a lock effectively renews its duration instead of adding extra time to it. For instance, if a 1000ms lock is extended by 1000ms after 500ms pass, it will only last for a total of 1500ms, not 2000ms. This approach is consistent with the [Node.js Redlock implementation](https://www.npmjs.com/package/redlock). See the [extend script](https://github.com/hexcowboy/rslock/blob/main/src/lock.rs#L22-L30).\n\n## Tests\n\nMake sure you have Docker running since all tests use `testcontainers`. Run tests with:\n\n```\ncargo test --all-features\n```\n\n## Examples\n\nStart the redis servers mentioned in the example code:\n\n```bash\ndocker compose -f examples/docker-compose.yml up -d\n```\n\nRun the examples:\n\n```bash\ncargo run --example basic\ncargo run --example shared_lock\ncargo run --example from_clients\n```\n\nStop the redis servers:\n\n```bash\ndocker compose -f examples/docker-compose.yml down\n```\n\n## Contribute\n\nIf you find bugs or want to help otherwise, please [open an issue](https://github.com/hexcowboy/rslock/issues).\n\n## License\n\nBSD. See [LICENSE](LICENSE).\n\n[docs badge]: https://img.shields.io/badge/docs.rs-rustdoc-green\n[crates.io]: https://crates.io/crates/rslock\n[docs.rs]: https://docs.rs/rslock/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexcowboy%2Frslock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexcowboy%2Frslock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexcowboy%2Frslock/lists"}