{"id":22598526,"url":"https://github.com/nilorg/sync","last_synced_at":"2026-04-28T22:32:29.323Z","repository":{"id":57538732,"uuid":"287518533","full_name":"nilorg/sync","owner":"nilorg","description":"distributed  sync lock 分布式同步锁","archived":false,"fork":false,"pushed_at":"2025-08-03T06:06:12.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-08T14:46:25.571Z","etag":null,"topics":["distributed-lock","golang","lock","redis","redis-distributed-lock"],"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/nilorg.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-08-14T11:35:52.000Z","updated_at":"2025-08-03T06:06:15.000Z","dependencies_parsed_at":"2025-09-08T14:31:49.677Z","dependency_job_id":"f21af652-49c1-4c19-850a-88f73c608415","html_url":"https://github.com/nilorg/sync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nilorg/sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilorg%2Fsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilorg%2Fsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilorg%2Fsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilorg%2Fsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilorg","download_url":"https://codeload.github.com/nilorg/sync/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilorg%2Fsync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32402666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","golang","lock","redis","redis-distributed-lock"],"created_at":"2024-12-08T11:06:08.515Z","updated_at":"2026-04-28T22:32:29.318Z","avatar_url":"https://github.com/nilorg.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sync\n\ndistributed  sync lock\n\n分布式同步锁（支持 Redis 实现）\n\n## 特性\n- 支持分布式互斥锁\n- 支持阻塞等待加锁（LockWait）\n- 支持自定义锁超时、重试间隔\n\n## 安装\n```shell\ngo get github.com/nilorg/sync\n```\n\n## 快速开始\n```go\nimport (\n    \"context\"\n    \"github.com/go-redis/redis/v8\"\n    \"github.com/nilorg/sync\"\n)\n\nfunc main() {\n    rdb := redis.NewClient(\u0026redis.Options{\n        Addr: \"localhost:6379\",\n    })\n    rs := sync.NewRedisSync(rdb)\n    m := rs.NewMutex(\"my_key\")\n    // 普通加锁\n    if err := m.Lock(); err != nil {\n        // 处理加锁失败\n    }\n    // 解锁\n    _ = m.Unlock()\n\n    // 阻塞等待加锁\n    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n    defer cancel()\n    if err := m.LockWait(ctx); err != nil {\n        // 处理超时或取消\n    }\n    _ = m.Unlock()\n}\n```\n\n## 接口说明\n\n### Mutexer\n```\ntype Mutexer interface {\n    Lock() error\n    Unlock() error\n}\n```\n\n### WaitableMutexer\n```\ntype WaitableMutexer interface {\n    Mutexer\n    LockWait(ctx context.Context) error // 阻塞直到加锁成功或上下文取消\n}\n```\n\n## 测试\n```shell\ngo test -v\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilorg%2Fsync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilorg%2Fsync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilorg%2Fsync/lists"}