{"id":18639152,"url":"https://github.com/charconstpointer/dlock","last_synced_at":"2025-11-04T16:30:34.867Z","repository":{"id":192448794,"uuid":"686742215","full_name":"charconstpointer/dlock","owner":"charconstpointer","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-03T19:50:25.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T09:29:52.699Z","etag":null,"topics":["distributed","distributed-lock","distributed-locks","leader","leader-election","lock","locks"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charconstpointer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-03T19:42:04.000Z","updated_at":"2023-09-03T19:51:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f9647ed-aca3-4080-a786-8567c6e0741b","html_url":"https://github.com/charconstpointer/dlock","commit_stats":null,"previous_names":["charconstpointer/dlock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charconstpointer%2Fdlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charconstpointer%2Fdlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charconstpointer%2Fdlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charconstpointer%2Fdlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charconstpointer","download_url":"https://codeload.github.com/charconstpointer/dlock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239436512,"owners_count":19638329,"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","distributed-lock","distributed-locks","leader","leader-election","lock","locks"],"created_at":"2024-11-07T05:45:44.457Z","updated_at":"2025-11-04T16:30:34.836Z","avatar_url":"https://github.com/charconstpointer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dlock Locking Library\n\ndlock provides a unified way to acquire and manage distributed locks using various 3rd party backends.\n\n\n## Introduction\n\nDistributed systems often require coordination and synchronization to avoid conflicts and ensure smooth operation. dlock simplifies this process by offering an easy-to-use interface for acquiring and managing distributed locks.\n\nHere's what you can do with this library:\n\n- Acquire locks with a customizable time-to-live (TTL).\n- Refresh locks to prevent automatic expiration.\n- Retry lock acquisition with a customizable interval and limit.\n\n## Supported Backends\n- SoonTM\n\n## Installation\n\n```shell\ngo get github.com/charconstpointer/dlock\n```\n\n# Usage\n\n## Lock Configuration\n\nBefore acquiring a lock, you can configure its behavior using the LockConfig struct and various LockOpt functions.\n\n```go\ntype LockConfig struct {\n    // TTL is the time-to-live of the lock. If not refreshed within this time, it will be released.\n    TTL time.Duration `json:\"ttl\"`\n    // RefreshInterval is the interval at which the lock is refreshed.\n    RefreshInterval time.Duration `json:\"refresh_interval\"`\n    // RetryInterval is the interval at which the lock is retried if held by another client.\n    RetryInterval time.Duration `json:\"retry_interval\"`\n    // RetryLimit is the maximum number of retry attempts before giving up.\n    RetryLimit int `json:\"retry_limit\"`\n}\n```\n\nHere are some configuration options:\n\n- WithTTL: Set the time-to-live (TTL) of the lock.\n- WithRefreshInterval: Configure the refresh interval of the lock.\n- WithRetryInterval: Customize the retry interval for acquiring the lock.\n- WithRetryLimit: Set the maximum retry attempts before giving up.\n\n## Acquiring a Lock\n\nTo acquire a lock, you can use the Locker interface:\n\n```go\ntype Locker interface {\n    Lock(key, value string, opts ...LockOpt) (*Lock, error)\n}\n```\n\nHere's an example of acquiring a lock:\n\n```go\nlocker := NewLocker() // Initialize your locker instance\nlock, err := locker.Lock(\"resource-key\", \"unique-value\", WithTTL(time.Minute), WithRetryLimit(3))\nif err != nil {\n    // Handle lock acquisition failure\n} else {\n    // You've acquired the lock!\n    // Access your critical resource here.\n    defer lock.Release() // Release the lock when done.\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharconstpointer%2Fdlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharconstpointer%2Fdlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharconstpointer%2Fdlock/lists"}