2017 © Pedro Peláez
 

library redlock-php

Redis distributed locks in PHP

image

signe/redlock-php

Redis distributed locks in PHP

  • Thursday, June 23, 2016
  • by signe
  • Repository
  • 2 Watchers
  • 4 Stars
  • 28,472 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

redlock-php - Redis distributed locks in PHP, (*1)

Based on Redlock-rb by Salvatore Sanfilippo, descendant of ronnylt/redlock-php which was abandoned in early 2015., (*2)

This library implements the Redis-based distributed lock manager algorithm described in this Redis article., (*3)

To create a lock manager:, (*4)

Locks can be provided using an array of server tuples made up of the server name (required), connection port (optional), and connection timeout (optional), or by using already-connected Redis objects,, (*5)

$server = new \Redis;
$server->connect('127.0.0.1');

$servers = [
    ['127.0.0.1', 6379, 0.01],
    ['127.0.0.1'],
    $server,
];

$redLock = new RedLock($servers);

To acquire a lock:, (*6)


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

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., (*7)

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

Array
(
    [validity] => 9897.3020019531
    [resource] => my_resource_name
    [token] => 53771bfa1e775
)
  • 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:, (*9)

    $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., (*10)

The retry delay is actually chosen at random between $retryDelay / 2 milliseconds and the specified $retryDelay value., (*11)

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., (*12)

The Versions

23/06 2016

dev-master

9999999-dev

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php >= 5.4
  • ext-redis *

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

23/06 2016

1.0.5

1.0.5.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php >= 5.4
  • ext-redis *

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

23/06 2016

1.0.4

1.0.4.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php >= 5.4
  • ext-redis >= 2.2.5

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

10/05 2016

1.0.3

1.0.3.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php >= 5.4
  • ext-redis ~2.2.5

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

24/01 2016

1.0.2

1.0.2.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

14/10 2015

1.0.1

1.0.1.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg

14/10 2015

1.0

1.0.0.0

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

The Development Requires

by Ronny Lopez
by Katherine Rossiter
by Henrik Tudborg