{"id":13526502,"url":"https://github.com/go-redsync/redsync","last_synced_at":"2025-05-12T15:25:25.202Z","repository":{"id":37493510,"uuid":"50891360","full_name":"go-redsync/redsync","owner":"go-redsync","description":"Distributed mutual exclusion lock using Redis for Go","archived":false,"fork":false,"pushed_at":"2024-08-19T08:21:26.000Z","size":602,"stargazers_count":3624,"open_issues_count":4,"forks_count":336,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-23T17:13:28.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://redis.io/topics/distlock","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-redsync.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":"2016-02-02T03:30:12.000Z","updated_at":"2025-04-23T04:34:39.000Z","dependencies_parsed_at":"2023-02-19T10:31:20.012Z","dependency_job_id":"d67fe906-6929-47d3-9c8a-641865c0856b","html_url":"https://github.com/go-redsync/redsync","commit_stats":{"total_commits":162,"total_committers":41,"mean_commits":3.951219512195122,"dds":0.5123456790123457,"last_synced_commit":"b292c9fb1fd21ee51789ca367a124194f8f66cf0"},"previous_names":["redsync/redsync"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-redsync%2Fredsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-redsync%2Fredsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-redsync%2Fredsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-redsync%2Fredsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-redsync","download_url":"https://codeload.github.com/go-redsync/redsync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253764500,"owners_count":21960588,"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-08-01T06:01:30.681Z","updated_at":"2025-05-12T15:25:25.155Z","avatar_url":"https://github.com/go-redsync.png","language":"Go","readme":"# Redsync\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/go-redsync/redsync/v4.svg)](https://pkg.go.dev/github.com/go-redsync/redsync/v4) [![Build Status](https://travis-ci.org/go-redsync/redsync.svg?branch=master)](https://travis-ci.org/go-redsync/redsync) \n\nRedsync provides a Redis-based distributed mutual exclusion lock implementation for Go as described in [this post](http://redis.io/topics/distlock). A reference library (by [antirez](https://github.com/antirez)) for Ruby is available at [github.com/antirez/redlock-rb](https://github.com/antirez/redlock-rb).\n\n## Installation\n\nInstall Redsync using the go get command:\n\n    $ go get github.com/go-redsync/redsync/v4\n\nTwo driver implementations will be installed; however, only the one used will be included in your project.\n\n * [Redigo](https://github.com/gomodule/redigo)\n * [Go-redis](https://github.com/go-redis/redis)\n\nSee the [examples](examples) folder for usage of each driver.\n\n## Documentation\n\n- [Reference](https://godoc.org/github.com/go-redsync/redsync)\n\n## Usage\n\nError handling is simplified to `panic` for shorter example.\n\n```go\npackage main\n\nimport (\n\tgoredislib \"github.com/redis/go-redis/v9\"\n\t\"github.com/go-redsync/redsync/v4\"\n\t\"github.com/go-redsync/redsync/v4/redis/goredis/v9\"\n)\n\nfunc main() {\n\t// Create a pool with go-redis (or redigo) which is the pool redisync will\n\t// use while communicating with Redis. This can also be any pool that\n\t// implements the `redis.Pool` interface.\n\tclient := goredislib.NewClient(\u0026goredislib.Options{\n\t\tAddr: \"localhost:6379\",\n\t})\n\tpool := goredis.NewPool(client) // or, pool := redigo.NewPool(...)\n\n\t// Create an instance of redisync to be used to obtain a mutual exclusion\n\t// lock.\n\trs := redsync.New(pool)\n\n\t// Obtain a new mutex by using the same name for all instances wanting the\n\t// same lock.\n\tmutexname := \"my-global-mutex\"\n\tmutex := rs.NewMutex(mutexname)\n\n\t// Obtain a lock for our given mutex. After this is successful, no one else\n\t// can obtain the same lock (the same mutex name) until we unlock it.\n\tif err := mutex.Lock(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Do your work that requires the lock.\n\n\t// Release the lock so other processes or threads can obtain a lock.\n\tif ok, err := mutex.Unlock(); !ok || err != nil {\n\t\tpanic(\"unlock failed\")\n\t}\n}\n```\n\n## Contributing\n\nContributions are welcome.\n\n## License\n\nRedsync is available under the [BSD (3-Clause) License](https://opensource.org/licenses/BSD-3-Clause).\n\n## Disclaimer\n\nThis code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in production environments.\n\n## Real World Uses\n\nBelow is a list of public, open source projects that use Redsync:\n\n- [Sourcegraph](https://github.com/sourcegraph/sourcegraph): Universal code search and intelligence platform. Uses Redsync in an internal cache implementation.\n- [Open Match](https://github.com/googleforgames/open-match) by Google: Flexible, extensible, and scalable video game matchmaking. Uses Redsync with its state store implementation.\n- [Gocron](https://github.com/go-co-op/gocron) by go-co-op: gocron is a job distributed scheduling package which lets you run Go functions at pre-determined intervals using a simple, human-friendly syntax. Uses Redsync with its distributed job scheduler implementation.\n\nIf you are using Redsync in a project please send a pull request to add it to the list.\n","funding_links":[],"categories":["开源类库","Go"],"sub_categories":["数据库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-redsync%2Fredsync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-redsync%2Fredsync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-redsync%2Fredsync/lists"}