{"id":13817267,"url":"https://github.com/go-locks/distlock","last_synced_at":"2025-05-15T19:31:05.203Z","repository":{"id":57486549,"uuid":"167495191","full_name":"go-locks/distlock","owner":"go-locks","description":"The universal component of distributed locks in golang , support redis and postgresql","archived":false,"fork":false,"pushed_at":"2019-02-15T07:13:41.000Z","size":22,"stargazers_count":62,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-19T14:43:02.001Z","etag":null,"topics":["distlock","distributed","distributed-lock","go","golang","lock","locks","mutex","postgresql","redis","rwmutex"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-locks.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}},"created_at":"2019-01-25T06:14:41.000Z","updated_at":"2024-01-19T10:26:04.000Z","dependencies_parsed_at":"2022-09-01T21:02:26.970Z","dependency_job_id":null,"html_url":"https://github.com/go-locks/distlock","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-locks%2Fdistlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-locks%2Fdistlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-locks%2Fdistlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-locks%2Fdistlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-locks","download_url":"https://codeload.github.com/go-locks/distlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254407272,"owners_count":22066205,"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","go","golang","lock","locks","mutex","postgresql","redis","rwmutex"],"created_at":"2024-08-04T06:00:38.827Z","updated_at":"2025-05-15T19:31:04.900Z","avatar_url":"https://github.com/go-locks.png","language":"Go","funding_links":[],"categories":["Misc"],"sub_categories":[],"readme":"# Go-Locks [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n通用的Golang分布式锁组件，更多使用案例详见 [examples](https://github.com/go-locks/examples)\n\n\n## Driver列表\n\n若有意向贡献未完成的驱动代码，请通过 [ISSUES](https://github.com/go-locks/distlock/issues) 或 邮箱 `249008728@qq.com` 联系我\n\n| Driver | 代码完成度 | 测试完成度 | 依赖包                                                | 使用说明                                                    |\n| :----- | :--------: | :--------: | :---------------------------------------------------- | :---------------------------------------------------------- |\n| redis  | 100%       | 100%       | [letsfire/redigo](https://github.com/letsfire/redigo) | 详见 [README.md](https://github.com/go-locks/redis-driver)  |\n| pgsql  | 100%       | 100%       | [lib/pq](https://github.com/lib/pq)                   | 详见 [README.md](https://github.com/go-locks/pgsql-driver)  |\n| etcd   | 未完成     | 未测试     | [etcd/client](https://go.etcd.io/etcd/client)         | 详见 [README.md](https://github.com/go-locks/etcd-driver)   |\n| etcdv3 | 未完成     | 未测试     | [etcd/clientv3](https://go.etcd.io/etcd/clientv3)     | 详见 [README.md](https://github.com/go-locks/etcdv3-driver) |\n\n\n## 方法说明\n\n配置项 `mutex.OptFunc` 以及返回值锁的使用详见 [mutex/README.md](https://github.com/go-locks/distlock/tree/master/mutex)\n\n- **NewMutex(name string, optFuncs ...mutex.OptFunc) (\\*mutex.Mutex, error)**  \n创建互斥锁，若 `name` 已用于创建读写锁则返回 `error`，本方法单例模式\n- **NewRWMutex(name string, optFuncs ...mutex.OptFunc) (\\*mutex.RWMutex, error)**  \n创建读写锁，若 `name` 已用于创建互斥锁则返回 `error`，本方法单例模式\n\n\n## 注意事项\n\n* 不可重入（如果您有强烈的需求场景，请通过 [ISSUES](https://github.com/go-locks/distlock/issues) 提供反馈）\n* 非公平锁（Golang的本地锁 `sync.Locker` 视乎也不是公平锁，若您有需求或建议，请通过 [ISSUES](https://github.com/go-locks/distlock/issues) 提供反馈）\n* 有互斥锁 `mutex` 和 读写锁 `rwmutex` 两种类型，具体支持程度详见各个 `Driver` 对应的 `README.md`\n* 虽有完整的单元测试，但暂未经过实际项目考验，故慎用于生产环境，如有问题请通过 [ISSUES](https://github.com/go-locks/distlock/issues) 来共同完善\n\n\n## 项目结构\n\n* 主线调用层级为 `distlock.go` -\u003e `mutex.go` -\u003e `driver.go`\n* `distlock.go` 提供了创建锁的工厂类，单例模式（相同名称的锁有且仅有一个，有且仅为一种）\n* `mutex.go`提供了各类锁的实现，欢迎各位同学贡献其他类型锁，详见 [mutex/README.md](https://github.com/go-locks/distlock/tree/master/mutex)\n* `driver.go`提供驱动接口的定义，欢迎各位同学贡献其他驱动，详见 [driver/README.md](https://github.com/go-locks/distlock/tree/master/driver)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-locks%2Fdistlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-locks%2Fdistlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-locks%2Fdistlock/lists"}