{"id":15687266,"url":"https://github.com/xdpcs/redis-lock","last_synced_at":"2025-05-07T19:41:13.350Z","repository":{"id":182065444,"uuid":"665854101","full_name":"XdpCs/redis-lock","owner":"XdpCs","description":"Distributed lock based on redis.","archived":false,"fork":false,"pushed_at":"2023-08-29T12:47:58.000Z","size":34,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-04T22:45:44.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/XdpCs.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":"2023-07-13T06:42:05.000Z","updated_at":"2023-11-10T02:04:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"171f5164-dbf1-4b7f-934d-2d0047507aef","html_url":"https://github.com/XdpCs/redis-lock","commit_stats":null,"previous_names":["xdpcs/redis-lock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XdpCs%2Fredis-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XdpCs%2Fredis-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XdpCs%2Fredis-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XdpCs%2Fredis-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XdpCs","download_url":"https://codeload.github.com/XdpCs/redis-lock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252945234,"owners_count":21829559,"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":[],"created_at":"2024-10-03T17:46:21.999Z","updated_at":"2025-05-07T19:41:13.344Z","avatar_url":"https://github.com/XdpCs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redis-lock\n\n![GitHub watchers](https://img.shields.io/github/watchers/XdpCs/redis-lock?style=social)\n![GitHub stars](https://img.shields.io/github/stars/XdpCs/redis-lock?style=social)\n![GitHub forks](https://img.shields.io/github/forks/XdpCs/redis-lock?style=social)\n![GitHub last commit](https://img.shields.io/github/last-commit/XdpCs/redis-lock?style=flat-square)\n![GitHub repo size](https://img.shields.io/github/repo-size/XdpCs/redis-lock?style=flat-square)\n![GitHub license](https://img.shields.io/github/license/XdpCs/redis-lock?style=flat-square)\n\nDistributed lock based on [redis](https://redis.io/docs/manual/patterns/distributed-locks/).\n\nredis-lock supports watchdog mechanism in [redisson](https://github.com/redisson/redisson).\n\n## install\n\n`go get`\n\n```shell\ngo get -u github.com/XdpCs/redis-lock\n```\n\n`go mod`\n\n```shell\nrequire github.com/XdpCs/redis-lock latest\n```\n\n## example\n\nError handling is simplified to panic for shorter example.\n\nYou can run this program in this [directory](./example/main.go).\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"time\"\n\n\tredislock \"github.com/XdpCs/redis-lock\"\n\t\"github.com/redis/go-redis/v9\"\n)\n\nfunc main() {\n\t// init context\n\tctx := context.Background()\n\t// init redis client\n\trdb := redis.NewClient(\u0026redis.Options{\n\t\tAddr: \":6379\",\n\t})\n\t// close redis client\n\tdefer rdb.Close()\n\t// flush redis\n\t_ = rdb.FlushDB(ctx).Err()\n\t// init redislock client\n\tclient, err := redislock.NewDefaultClient(rdb)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// try lock with default parameter\n\tmutex, err := client.TryLock(ctx, \"XdpCs\", -1)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdefer func(mutex *redislock.Mutex, ctx context.Context) {\n\t\t// unlock mutex\n\t\terr := mutex.Unlock(ctx)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}(mutex, ctx)\n\ttime.Sleep(time.Second * 30)\n}\n```\n\n## License\n\nredis-lock is under the [MIT](LICENSE). Please refer to LICENSE for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdpcs%2Fredis-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdpcs%2Fredis-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdpcs%2Fredis-lock/lists"}