{"id":16101733,"url":"https://github.com/kelunik/redis-mutex","last_synced_at":"2025-03-18T08:30:29.524Z","repository":{"id":32965039,"uuid":"36580779","full_name":"kelunik/redis-mutex","owner":"kelunik","description":"Mutex implementation using Redis.","archived":false,"fork":false,"pushed_at":"2019-01-20T22:07:53.000Z","size":21,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T18:12:25.201Z","etag":null,"topics":["amphp","mutex","redis","redis-mutex"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kelunik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-31T00:07:35.000Z","updated_at":"2025-03-05T20:15:48.000Z","dependencies_parsed_at":"2022-08-07T19:01:23.265Z","dependency_job_id":null,"html_url":"https://github.com/kelunik/redis-mutex","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Fredis-mutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Fredis-mutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Fredis-mutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Fredis-mutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelunik","download_url":"https://codeload.github.com/kelunik/redis-mutex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910814,"owners_count":20367545,"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":["amphp","mutex","redis","redis-mutex"],"created_at":"2024-10-09T18:50:51.039Z","updated_at":"2025-03-18T08:30:29.215Z","avatar_url":"https://github.com/kelunik.png","language":"PHP","funding_links":[],"categories":["Redis"],"sub_categories":["Tunnel"],"readme":"# Redis Mutex [![Build Status](https://travis-ci.org/kelunik/redis-mutex.svg?branch=master)](https://travis-ci.org/kelunik/redis-mutex)\n\nDistributed mutual exclusion built upon the [Amp concurrency framework](https://github.com/amphp/amp) and [Redis](http://redis.io).\n\n## Basic Example\n\n```php\n$mutex = new Mutex(...);\n\n// ...\n\ntry {\n    $token = bin2hex(random_bytes(16));\n    yield $mutex-\u003elock($sessionId, $token);\n\n    // Code here will only be executed in one client at a time.\n    // If it takes longer than your specified TTL, you have to\n    // renew the lock, see next example.\n\n    yield $mutex-\u003eunlock($sessionId, $token);\n} catch (MutexException $e) {\n    // ...\n}\n```\n\n## Renew Example\n\n```php\n$mutex = new Mutex(...);\n$locks = [];\n\nLoop::repeat(1000, function () use ($mutex, $locks) {\n    foreach ($locks as $id =\u003e $token) {\n        $mutex-\u003erenew($id, $token);\n    }\n});\n\n// ...\n\ntry {\n    $token = bin2hex(random_bytes(16));\n    yield $mutex-\u003elock($sessionId, $token);\n    $locks[$sessionId] = $token;\n\n    // Code here will only be executed in one client at a time.\n    // Your lock will automatically be renewed by the reactor\n    // repeat above. Don't do blocking things here (you should never\n    // do that with Amp anyway), otherwise the reactor will not\n    // be able to schedule the renewal.\n\n    unset($locks[$sessionId]);\n    yield $mutex-\u003eunlock($sessionId, $token);\n} catch (MutexException $e) {\n    // ...\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Fredis-mutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelunik%2Fredis-mutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Fredis-mutex/lists"}