{"id":25659481,"url":"https://github.com/itcomusic/redismutex","last_synced_at":"2026-05-19T07:03:32.456Z","repository":{"id":65298891,"uuid":"585911699","full_name":"itcomusic/redismutex","owner":"itcomusic","description":"Distributed locking implementation using Redis","archived":false,"fork":false,"pushed_at":"2023-02-23T17:55:07.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T05:14:09.010Z","etag":null,"topics":["distributed","go","golang","lock","mutex","redis","rwlock"],"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/itcomusic.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-01-06T12:27:47.000Z","updated_at":"2024-03-26T11:28:26.000Z","dependencies_parsed_at":"2024-06-20T04:26:07.646Z","dependency_job_id":"629321a2-f9a9-4600-b8c6-84420b821028","html_url":"https://github.com/itcomusic/redismutex","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Fredismutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Fredismutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Fredismutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Fredismutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itcomusic","download_url":"https://codeload.github.com/itcomusic/redismutex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240400334,"owners_count":19795333,"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":["distributed","go","golang","lock","mutex","redis","rwlock"],"created_at":"2025-02-24T01:17:21.264Z","updated_at":"2025-10-24T20:05:00.858Z","avatar_url":"https://github.com/itcomusic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RWMutex\n\n[![build-img]][build-url]\n[![pkg-img]][pkg-url]\n[![coverage-img]][coverage-url]\n\nDistributed rw locking implementation using [Redis](https://redis.io/docs/manual/patterns/distributed-locks/) with auto extended lock expiration. \nRWMutex can work in write prefer mode, when readers do not acquire lock if writer has declared intention to lock.\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n    \n\t\"github.com/redis/redis/v9\"\n\t\"github.com/itcomusic/redismutex\"\n)\n\nfunc main() {\n    // connect to redis\n    rc := redis.NewClient(\u0026redis.Options{\n        Network: \"tcp\",\n        Addr:    \"127.0.0.1:6379\",\n    })\n    defer rc.Close()\n\n    // init mutex\n    mx := redismutex.NewMutex(rc, \"mutex_name\")\n\n    // lock, optionally add key and lock_key will be \"mutex_name:key\"\n    lock, ok := mx.Lock(redismutex.WithKey(\"key\")) // also available RLock, TryLock, TryRLock\n    if !ok {\n        log.Fatalln(\"could not obtain lock, disconnected from redis?\")\n    }\n    defer lock.Unlock()\n\n    // lock implements interface context.Context\n    handler := func(ctx context.Context) { \n        select {\n        case \u003c-ctx.Done():\n            fmt.Println(\"lock expired\")\n\t\t\t\n        default:\n            fmt.Println(\"lock active\")\n        }\n    }\n\n    fmt.Printf(\"lock %q! \\n\", lock.Key())\n    handler(lock) \n}\n```\n\n## License\n[MIT License](LICENSE)\n\n[build-img]: https://github.com/itcomusic/redismutex/workflows/test/badge.svg\n[build-url]: https://github.com/itcomusic/redismutex/actions\n[pkg-img]: https://pkg.go.dev/badge/github.com/itcomusic/redismutex.svg\n[pkg-url]: https://pkg.go.dev/github.com/itcomusic/redismutex\n[coverage-img]: https://codecov.io/gh/itcomusic/redismutex/branch/main/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/itcomusic/redismutex","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitcomusic%2Fredismutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitcomusic%2Fredismutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitcomusic%2Fredismutex/lists"}