{"id":13412635,"url":"https://github.com/bsm/redislock","last_synced_at":"2025-05-14T01:05:13.997Z","repository":{"id":40244388,"uuid":"193489892","full_name":"bsm/redislock","owner":"bsm","description":"Simplified distributed locking implementation using Redis","archived":false,"fork":false,"pushed_at":"2024-03-21T12:29:37.000Z","size":70,"stargazers_count":1557,"open_issues_count":2,"forks_count":162,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-03T06:05:42.731Z","etag":null,"topics":["distlock","distributed","distributed-lock","golang","lock","redis"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-06-24T11:10:10.000Z","updated_at":"2025-04-01T14:00:37.000Z","dependencies_parsed_at":"2023-11-24T16:29:16.297Z","dependency_job_id":"9325d9e9-6b88-4ca8-b8e3-568bf1d0b172","html_url":"https://github.com/bsm/redislock","commit_stats":{"total_commits":46,"total_committers":10,"mean_commits":4.6,"dds":0.4347826086956522,"last_synced_commit":"bfd385b776d1e069eca5cb6b6cc41d635cbb4e55"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fredislock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fredislock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fredislock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fredislock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsm","download_url":"https://codeload.github.com/bsm/redislock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248201991,"owners_count":21064240,"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":["distlock","distributed","distributed-lock","golang","lock","redis"],"created_at":"2024-07-30T20:01:27.074Z","updated_at":"2025-04-10T10:47:42.506Z","avatar_url":"https://github.com/bsm.png","language":"Go","readme":"# redislock\n\n[![Test](https://github.com/bsm/redislock/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/redislock/actions/workflows/test.yml)\n[![GoDoc](https://godoc.org/github.com/bsm/redislock?status.png)](http://godoc.org/github.com/bsm/redislock)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nSimplified distributed locking implementation using [Redis](http://redis.io/topics/distlock).\nFor more information, please see examples.\n\n## Examples\n\n```go\nimport (\n  \"context\"\n  \"fmt\"\n  \"log\"\n  \"time\"\n\n  \"github.com/bsm/redislock\"\n  \"github.com/redis/go-redis/v9\"\n)\n\nfunc main() {\n\t// Connect to redis.\n\tclient := redis.NewClient(\u0026redis.Options{\n\t\tNetwork:\t\"tcp\",\n\t\tAddr:\t\t\"127.0.0.1:6379\",\n\t})\n\tdefer client.Close()\n\n\t// Create a new lock client.\n\tlocker := redislock.New(client)\n\n\tctx := context.Background()\n\n\t// Try to obtain lock.\n\tlock, err := locker.Obtain(ctx, \"my-key\", 100*time.Millisecond, nil)\n\tif err == redislock.ErrNotObtained {\n\t\tfmt.Println(\"Could not obtain lock!\")\n\t} else if err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\t// Don't forget to defer Release.\n\tdefer lock.Release(ctx)\n\tfmt.Println(\"I have a lock!\")\n\n\t// Sleep and check the remaining TTL.\n\ttime.Sleep(50 * time.Millisecond)\n\tif ttl, err := lock.TTL(ctx); err != nil {\n\t\tlog.Fatalln(err)\n\t} else if ttl \u003e 0 {\n\t\tfmt.Println(\"Yay, I still have my lock!\")\n\t}\n\n\t// Extend my lock.\n\tif err := lock.Refresh(ctx, 100*time.Millisecond, nil); err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\t// Sleep a little longer, then check.\n\ttime.Sleep(100 * time.Millisecond)\n\tif ttl, err := lock.TTL(ctx); err != nil {\n\t\tlog.Fatalln(err)\n\t} else if ttl == 0 {\n\t\tfmt.Println(\"Now, my lock has expired!\")\n\t}\n\n}\n```\n\n## Documentation\n\nFull documentation is available on [GoDoc](http://godoc.org/github.com/bsm/redislock)\n","funding_links":[],"categories":["分布式系统","Distributed Systems","开源类库","Go","Relational Databases"],"sub_categories":["SQL 查询语句构建库","Search and Analytic Databases","数据库","Advanced Console UIs","检索及分析资料库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fredislock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsm%2Fredislock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fredislock/lists"}