2017 © Pedro Peláez
 

library php-redlock

Redis distributed locks in PHP

image

kcyeu/php-redlock

Redis distributed locks in PHP

  • Tuesday, March 31, 2015
  • by kcyeu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 113 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PHP-Redlock

Redis distributed locks in PHP, (*1)

Based on Redlock-rb by Salvatore Sanfilippo and Redlock-php by Ronny López. This library implements the Redis-based distributed lock manager algorithm described in this blog post., (*2)

Support cluster mode using phpredis PECL extention., (*3)

To create a lock manager:, (*4)


$servers = array( array('127.0.0.1', 6379), array('127.0.0.1', 6380), array('127.0.0.1', 6381), ); $redLock = new RedLock($servers);

To acquire a lock:, (*5)


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

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

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

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

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

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

The Versions

31/03 2015

dev-master

9999999-dev

Redis distributed locks in PHP

  Sources   Download

LGPL-3.0+

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

26/03 2015

dev-cluster

dev-cluster

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

by Ronny Lopez

26/03 2015

dev-single

dev-single

Redis distributed locks in PHP

  Sources   Download

The Requires

  • php ~5.4
  • ext-redis ~2.2.5

 

by Ronny Lopez