PHPackages                             texthtml/php-lock-redis - 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. texthtml/php-lock-redis

Abandoned → [symfony/lock](/?search=symfony%2Flock)ArchivedLibrary

texthtml/php-lock-redis
=======================

redis lock

v1.2.0(6y ago)668.3k—0%6[1 issues](https://github.com/texthtml/php-lock-redis/issues)AGPL-3.0-or-laterPHPCI passing

Since Oct 18Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/texthtml/php-lock-redis)[ Packagist](https://packagist.org/packages/texthtml/php-lock-redis)[ RSS](/packages/texthtml-php-lock-redis/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (8)Used By (0)

php-lock-redis
==============

[](#php-lock-redis)

[![Build Status](https://camo.githubusercontent.com/14201da94a81eb9fe0516c312965506bab6267237df243e08e32a82b21ebe9f6/68747470733a2f2f7472617669732d63692e6f72672f7465787468746d6c2f7068702d6c6f636b2d72656469732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/texthtml/php-lock-redis)[![Latest Stable Version](https://camo.githubusercontent.com/e3e5b8bd9941be9e059dfe03ae4c87e2f3898c00d5f14bcad3c150507e4a66a5/68747470733a2f2f706f7365722e707567782e6f72672f7465787468746d6c2f7068702d6c6f636b2d72656469732f762f737461626c652e737667)](https://packagist.org/packages/texthtml/php-lock-redis)[![License](https://camo.githubusercontent.com/347a2ff2a478114f2bf5cf36c0c64b93624842c32129b3968cd9d537fffd850c/68747470733a2f2f706f7365722e707567782e6f72672f7465787468746d6c2f7068702d6c6f636b2d72656469732f6c6963656e73652e737667)](http://www.gnu.org/licenses/agpl-3.0.html)[![Total Downloads](https://camo.githubusercontent.com/d7f427f24251c7427f55d9e729fff1f26a1beee299d4e31a04237a605ccc4cb3/68747470733a2f2f706f7365722e707567782e6f72672f7465787468746d6c2f7068702d6c6f636b2d72656469732f646f776e6c6f6164732e737667)](https://packagist.org/packages/texthtml/php-lock-redis)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/15f0668dcdebcb8c01d2383b66c6804fb54769d11dd89c5567eb06e9426b2674/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7465787468746d6c2f7068702d6c6f636b2d72656469732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/texthtml/php-lock-redis/?branch=master)

[php-lock-redis](https://packagist.org/packages/texthtml/php-lock-redis) is an extension for [php-lock](https://packagist.org/packages/texthtml/php-lock) that makes locking on resources easy on distributed system using Redis. It can be used instead of file base locking to lock operations on a distributed system.

Installation
------------

[](#installation)

With Composer :

```
composer require texthtml/php-lock-redis
```

Usage
-----

[](#usage)

You can create an object that represent a lock on a resource. You can then try to acquire that lock by calling `$lock->acquire()`. If the lock fail it will throw an `Exception` (useful for CLI tools built with [Symfony Console Components documentation](http://symfony.com/doc/current/components/console/introduction.html)). If the lock is acquired the program can continue.

### Locking a ressource

[](#locking-a-ressource)

```
use TH\RedisLock\RedisSimpleLockFactory;

$redisClient = new \Predis\Client;
$factory = new RedisSimpleLockFactory($redisClient);
$lock = $factory->create('lock identifier');

$lock->acquire();

// other processes that try to acquire a lock on 'lock identifier' will fail

// do some stuff

$lock->release();

// other processes can now acquire a lock on 'lock identifier'
```

### Auto release

[](#auto-release)

`$lock->release()` is called automatically when the lock is destroyed so you don't need to manually release it at the end of a script or if it goes out of scope.

```
use TH\RedisLock\RedisSimpleLockFactory;

function batch() {
    $redisClient = new \Predis\Client;
    $factory = new RedisSimpleLockFactory($redisClient);
    $lock = $factory->create('lock identifier');
    $lock->acquire();

    // lot of stuff
}

batch();

// the lock will be released here even if $lock->release() is not called in batch()
```

Limitations
-----------

[](#limitations)

### Validity time

[](#validity-time)

If a client crashes before releasing the lock (or forget to release it), no other clients would be able to acquire the lock again. To avoid Deadlock, `RedisSimpleLock` locks have a validity time at witch the lock key will expire. But be careful, if the operation is too long, another client might acquire the lock too.

### Mutual exclusion

[](#mutual-exclusion)

Because `RedisSimpleLock` does not implements the [RedLock algorithm](http://redis.io/topics/distlock), it have a limitation : with a master slave replication, a race condition can occurs when the master crashes before the lock key is transmitted to the slave. In this case a second client could acquire the same lock.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance45

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~437 days

Total

4

Last Release

2543d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3943b5c35797d1ede53aaed3d6812e4cf5b2dba7619a00dc7a381480a7b3d330?d=identicon)[mathroc](/maintainers/mathroc)

---

Top Contributors

[![mathroc](https://avatars.githubusercontent.com/u/291531?v=4)](https://github.com/mathroc "mathroc (16 commits)")[![text-html-renovate[bot]](https://avatars.githubusercontent.com/u/6465918?v=4)](https://github.com/text-html-renovate[bot] "text-html-renovate[bot] (10 commits)")[![im-bryan](https://avatars.githubusercontent.com/u/46322430?v=4)](https://github.com/im-bryan "im-bryan (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/texthtml-php-lock-redis/health.svg)

```
[![Health](https://phpackages.com/badges/texthtml-php-lock-redis/health.svg)](https://phpackages.com/packages/texthtml-php-lock-redis)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[api-platform/metadata

API Resource-oriented metadata attributes and factories

223.5M96](/packages/api-platform-metadata)[pdffiller/qless-php

PHP Bindings for qless

29113.2k1](/packages/pdffiller-qless-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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