{"id":46079057,"url":"https://github.com/amitaifrey/redisemaphore","last_synced_at":"2026-03-01T15:08:58.718Z","repository":{"id":253670950,"uuid":"844039862","full_name":"amitaifrey/redisemaphore","owner":"amitaifrey","description":"Redis-Based Distributed Semaphore Implementation, With Priority Queues","archived":false,"fork":false,"pushed_at":"2025-05-07T15:23:20.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T16:37:06.821Z","etag":null,"topics":["distributed","distributed-systems","golang","priority-queue","priority-scheduling","redis","semaphore"],"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/amitaifrey.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}},"created_at":"2024-08-18T07:32:21.000Z","updated_at":"2025-05-07T15:22:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"d33d816e-2901-4fda-99b9-f6fe9f658add","html_url":"https://github.com/amitaifrey/redisemaphore","commit_stats":null,"previous_names":["amitaifrey/redisemaphore"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/amitaifrey/redisemaphore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitaifrey%2Fredisemaphore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitaifrey%2Fredisemaphore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitaifrey%2Fredisemaphore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitaifrey%2Fredisemaphore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amitaifrey","download_url":"https://codeload.github.com/amitaifrey/redisemaphore/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitaifrey%2Fredisemaphore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29973306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T15:06:50.263Z","status":"ssl_error","status_checked_at":"2026-03-01T15:06:18.879Z","response_time":124,"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","distributed-systems","golang","priority-queue","priority-scheduling","redis","semaphore"],"created_at":"2026-03-01T15:08:58.273Z","updated_at":"2026-03-01T15:08:58.704Z","avatar_url":"https://github.com/amitaifrey.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redis-Based Semaphore Implementation, Optional Distribution and Priority Queues\n\nThis repository contains a Go implementation of a Redis-based semaphore mechanism that allows for distributed locking using Redis sorted sets. It also includes a mutex lock mechanism to ensure safe concurrent access. The distribution of the semaphore is based redis clusters, i.e. we rely on the correctness of the Redis cluster to ensure the semaphore's correctness.\n\nThe semaphore itself has priorty queues, which allows tasks to be scheduled in a specific order. This is useful for tasks that are preferred to be executed first, such as tasks that are more time-critical or tasks that have higher priority.\n\n## Features\n\n1. **Semaphore Acquisition and Release:**\n   - Acquire and release semaphores directly or via named queues.\n   - Configurable semaphore options (expiry, timeout, polling duration, etc.).\n\n2. **Mutex Locking:**\n   - Acquire and release mutex locks to prevent race conditions during semaphore operations.\n   - Configurable lock options (expiry, timeout, polling duration, etc.).\n\n## Installation\n\n```shell\ngo get github.com/amitaifrey/redisemaphore\n```\n\n## Getting Started\n### Prerequisites\n- Go (v1.18+)\n- Redis\n\n### Example Usage \n\n```go\npackage main\n\nimport (\n\t\"context\"\n    \"log\"\n\t\"time\"\n\n\t\"github.com/redis/go-redis/v9\"\n\t\"github.com/yourusername/redisemaphore\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\tclient := redis.NewUniversalClient(\u0026redis.UniversalOptions{Addrs: []string{\"localhost:6379\"}})\n\n\t// Initialize semaphore\n\tsem, err := redisemaphore.NewSemaphore(client, \"example-semaphore\", 5,\n\t\tredisemaphore.WithSemaphoreMutexExpiry(2*time.Minute),\n\t\tredisemaphore.WithSemaphorePollDur(200*time.Millisecond),\n\t)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Acquire semaphore\n\terr = sem.Acquire(ctx, \"my-key\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Do some work...\n\n\t// Release semaphore\n\terr = sem.Release(ctx, \"my-key\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n## Configuration Options\n\n### Semaphore Options\n\n- `WithSemaphoreMutexName(name string)`: Set a custom name for the mutex.\n- `WithSemaphoreMutexExpiry(expiry time.Duration)`: Set the expiry duration for the mutex.\n- `WithSemaphoreMutexTimeout(timeout time.Duration)`: Set the timeout duration for acquiring the mutex.\n- `WithSemaphoreDeleteTimeout(deleteTimeout time.Duration)`: Set the timeout duration for deleting keys from the semaphore set.\n- `WithSemaphorePollDur(pollDur time.Duration)`: Set the polling duration for the semaphore.\n- `WithSemaphoreQueueKeysByPrio(queueKeysByPrio ...string)`: Set the priority queue keys for the semaphore.\n\n### Mutex Options\n\n- `WithMutexPollDur(pollDur time.Duration)`: Set the polling duration for the mutex.\n- `WithMutexExpiry(expiry time.Duration)`: Set the expiry duration for the mutex.\n- `WithMutexTimeout(timeout time.Duration)`: Set the timeout duration for acquiring the mutex.\n\n## Error Handling\n\nCommon errors:\n- `ErrNoKeysLeft`: Indicates that no keys are left in the queues.\n- `ErrTimeout`: Indicates that a lock acquisition has timed out.\n\n## Contributing\n\nWe welcome contributions! Please fork the repository and submit a pull request for any improvements or bug fixes.\n\n## License\n\nThis project is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\n- [Go-Redis](https://github.com/redis/go-redis): A Go client for Redis.\n\n---\n\nBy using this repository, you agree to the terms and conditions of the accompanying License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitaifrey%2Fredisemaphore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famitaifrey%2Fredisemaphore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitaifrey%2Fredisemaphore/lists"}