{"id":23044824,"url":"https://github.com/tomarus/dlock","last_synced_at":"2025-07-12T16:34:56.573Z","repository":{"id":71890006,"uuid":"111025333","full_name":"tomarus/dlock","owner":"tomarus","description":"A distributed Redis backed lock package and commandline utility written in Go.","archived":false,"fork":false,"pushed_at":"2017-11-16T21:49:00.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T01:43:59.605Z","etag":null,"topics":["golang","lock"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomarus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2017-11-16T21:39:50.000Z","updated_at":"2017-11-16T21:40:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"cea4a0fe-523a-4716-84b7-b65a52ba0b88","html_url":"https://github.com/tomarus/dlock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomarus/dlock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomarus%2Fdlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomarus%2Fdlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomarus%2Fdlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomarus%2Fdlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomarus","download_url":"https://codeload.github.com/tomarus/dlock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomarus%2Fdlock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265024275,"owners_count":23699589,"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":["golang","lock"],"created_at":"2024-12-15T21:16:21.925Z","updated_at":"2025-07-12T16:34:56.553Z","avatar_url":"https://github.com/tomarus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/tomarus/dlock)](https://goreportcard.com/report/github.com/tomarus/dlock)\n[![GoDoc](https://godoc.org/github.com/tomarus/dlock?status.svg)](https://godoc.org/github.com/tomarus/dlock)\n\nDLock\n=====\n\nDLock is a basic distributed Redis backed lock package and commandline utility written in Go.\n\nIt's usage lives in crontabs running on multiple servers of which only a single server should perform a task.\n\n## Installation\n\n```\ngo install github.com/tomarus/dlock/cmd/dlock\n```\n\n## Example cron entries\n\nRunning a tool the first day of the month:\n\n```\n0 0 1 * * root dlock -name testing -redis redis:6379 \u0026\u0026 your_script.sh\n```\n\nThis crontab can be installed to many servers and it will run on only one server.\n\nThe dlock utility should not necessarily run from crontab ofcourse. This is just an example.\n\n## Exit codes\n\ndlock returns 0 when the lock was acquired successfully.\n\ndlock returns 1 when the lock was already held by someone else.\n\ndlock returns -1 when a redis error occurs. An errormessage is also logged to stderr in this case.\n\n## Full options\n\n```\ndlock -name name_of_lock -redis your_host:6379 -expire 300\n```\n\nYou cannot currently remove locks, you should let it expire instead. Expire should always be higher than the theoretical maximum runtime of your process and it should account for any time differences between servers.\n\n## Code example\n\nSuppose you have a daemon running on multiple servers which receive data at random intervals, like every few seconds of every few minutes.\n\nNow you want to create a global report on any server, but not more than once every 3 minutes:\n\n```\n\tfunc main() {\n\t\tdl, _ := dlock.New(\"addr:6379\", \"mykey\", 180)\n\t}\n\n\tfunc loop() {\n\t\treceiveSomeData()\n\t\tok, _ := dl.Acquire()\n\t\tif ok {\n\t\t\tmakeReport()\n\t\t}\n\t}\n```\n\n## Disclaimer\n\nThere are probably better tools which solve this problem, like zookeeper or specialized scheduling containers.\n\nThis tool was just built in a few hours because I needed it, and I didn't want to have too much dependencies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomarus%2Fdlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomarus%2Fdlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomarus%2Fdlock/lists"}