PHPackages                             kelunik/redis-mutex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. kelunik/redis-mutex

ActiveLibrary[Caching](/categories/caching)

kelunik/redis-mutex
===================

v0.2.2(7y ago)73.3k3[1 issues](https://github.com/kelunik/redis-mutex/issues)MITPHP

Since Feb 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kelunik/redis-mutex)[ Packagist](https://packagist.org/packages/kelunik/redis-mutex)[ RSS](/packages/kelunik-redis-mutex/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

Redis Mutex [![Build Status](https://camo.githubusercontent.com/095c8bbc9af2aafce319caff533271f3e1a8d18490d0c847a2343b80de32345d/68747470733a2f2f7472617669732d63692e6f72672f6b656c756e696b2f72656469732d6d757465782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kelunik/redis-mutex)
====================================================================================================================================================================================================================================================================================================

[](#redis-mutex-)

Distributed mutual exclusion built upon the [Amp concurrency framework](https://github.com/amphp/amp) and [Redis](http://redis.io).

Basic Example
-------------

[](#basic-example)

```
$mutex = new Mutex(...);

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);

    // Code here will only be executed in one client at a time.
    // If it takes longer than your specified TTL, you have to
    // renew the lock, see next example.

    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}
```

Renew Example
-------------

[](#renew-example)

```
$mutex = new Mutex(...);
$locks = [];

Loop::repeat(1000, function () use ($mutex, $locks) {
    foreach ($locks as $id => $token) {
        $mutex->renew($id, $token);
    }
});

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);
    $locks[$sessionId] = $token;

    // Code here will only be executed in one client at a time.
    // Your lock will automatically be renewed by the reactor
    // repeat above. Don't do blocking things here (you should never
    // do that with Amp anyway), otherwise the reactor will not
    // be able to schedule the renewal.

    unset($locks[$sessionId]);
    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}
```

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~265 days

Total

5

Last Release

2767d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/12852217f3369e8144bc9ce6ac2a2341c28c5512c5b3df5749bfbbd45b6877ff?d=identicon)[kelunik](/maintainers/kelunik)

---

Top Contributors

[![kelunik](https://avatars.githubusercontent.com/u/2743004?v=4)](https://github.com/kelunik "kelunik (27 commits)")[![trowski](https://avatars.githubusercontent.com/u/1628287?v=4)](https://github.com/trowski "trowski (1 commits)")

---

Tags

amphpmutexredisredis-mutex

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/kelunik-redis-mutex/health.svg)

```
[![Health](https://phpackages.com/badges/kelunik-redis-mutex/health.svg)](https://phpackages.com/packages/kelunik-redis-mutex)
```

###  Alternatives

[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.5k920.5k24](/packages/danog-madelineproto)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
