PHPackages                             ginnerpeace/redlock-php - 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. ginnerpeace/redlock-php

ActiveLibrary[Caching](/categories/caching)

ginnerpeace/redlock-php
=======================

Redis distributed locks in PHP

v1.0.0(6y ago)218.0kMITPHPPHP ^7.1.3CI failing

Since Jan 13Pushed 6y ago1 watchersCompare

[ Source](https://github.com/jay-youngn/redlock-php)[ Packagist](https://packagist.org/packages/ginnerpeace/redlock-php)[ Docs](https://github.com/ginnerpeace/redlock-php)[ RSS](/packages/ginnerpeace-redlock-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

redlock-php - Redis distributed locks in PHP
============================================

[](#redlock-php---redis-distributed-locks-in-php)

[![Total Downloads](https://camo.githubusercontent.com/dc0dbb26a57aa6d04b6d6348aba75665ba18d4d6176f6469f64bbedf7659f8de/68747470733a2f2f706f7365722e707567782e6f72672f67696e6e657270656163652f7265646c6f636b2d7068702f646f776e6c6f6164732e737667)](https://packagist.org/packages/ginnerpeace/redlock-php)[![Latest Stable Version](https://camo.githubusercontent.com/11114ddc3737113b5687cefdd745ce961eaa52e63e2e50a181df8b9595c92c6d/68747470733a2f2f706f7365722e707567782e6f72672f67696e6e657270656163652f7265646c6f636b2d7068702f762f737461626c652e737667)](https://packagist.org/packages/ginnerpeace/redlock-php)[![Latest Unstable Version](https://camo.githubusercontent.com/10e474af892c87218ee366f8adf40688c8b4caa31615cff3fea15780e5b795e7/68747470733a2f2f706f7365722e707567782e6f72672f67696e6e657270656163652f7265646c6f636b2d7068702f762f756e737461626c652e737667)](https://packagist.org/packages/ginnerpeace/redlock-php)[![License](https://camo.githubusercontent.com/053c11a167ac73994eea13cabb07635085c6ef89d4b4746edab1d25d59bb6ba3/68747470733a2f2f706f7365722e707567782e6f72672f67696e6e657270656163652f7265646c6f636b2d7068702f6c6963656e73652e737667)](https://packagist.org/packages/ginnerpeace/redlock-php)

Based on [Redlock-php](https://github.com/ronnylt/redlock-php) by [Ronny López](https://github.com/ronnylt)

Based on [Redlock-rb](https://github.com/antirez/redlock-rb) by [Salvatore Sanfilippo](https://github.com/antirez)

This library implements the Redis-based distributed lock manager algorithm [described in this blog post](http://antirez.com/news/77).

### Install

[](#install)

```
composer require ginnerpeace/redlock-php
```

### Example

[](#example)

> To create a lock manager

```
use Ginnerpeace\RedLock\RedLock;

// You can use any redis component to build the instance,
// Redis instance just need to implement the method: eval
$redLock = new RedLock([
    'servers' => [
        [
            // For ext-redis
            function ($host, $port, $timeout) {
                $redis = new \Redis();
                $redis->connect($host, $port, $timeout);
                return $redis;
            },
            ['127.0.0.1', 6379, 0.01]
        ],
        [
            // For Predis
            function ($dsn) {
                return new Predis\Client($dsn);
            },
            ['tcp://10.0.0.1:6379']
        ],
        [
            // For Laravel
            function ($name) {
                return RedisFacade::connection($name)->client();
            },
            ['redis']
        ],
    ],
]);
```

> To acquire a lock

```
$lock = $redLock->lock('my_resource_name', 1000);

// Or use dynamic retry param.
$retryTime = 10;
$lock = $redLock->lock('my_resource_name', 1000, $retryTime);
```

Where the resource name is an unique identifier of what you are trying to lock and 1000 is the number of milliseconds for the validity time.

The returned value is `[]` if the lock was not acquired (you may try again), otherwise an array representing the lock is returned, having three keys:

```
[
    'validity' => 9897.3020019531
    'resource' => 'my_resource_name',
    'token' => '22f8fd8d0f176ee2e1b7e676ae1f6c8b',
];
```

- validity, an integer representing the number of milliseconds the lock will be valid.
- resource, the name of the locked resource as specified by the user.
- token, a random token value which is used to safe reclaim the lock.

> To release a lock

```
$redLock->unlock($lock);
```

It is possible to setup the number of retries (by default 3) and the retry delay (by default 200 milliseconds) used to acquire the lock.

The retry delay is actually chosen at random between `$retryDelay / 2` milliseconds and the specified `$retryDelay` value.

**Disclaimer**: As stated in the original antirez's version, this code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2318d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d9e17941e70e1d054194601c63b3a4f522cb07d389a3a05ddecae3598f96125?d=identicon)[jay-youngn](/maintainers/jay-youngn)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ginnerpeace-redlock-php/health.svg)

```
[![Health](https://phpackages.com/badges/ginnerpeace-redlock-php/health.svg)](https://phpackages.com/packages/ginnerpeace-redlock-php)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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