2017 © Pedro Peláez
 

library autolock

Redis distributed locks in PHP

image

mmdtl/autolock

Redis distributed locks in PHP

  • Thursday, November 23, 2017
  • by mmdtllu
  • Repository
  • 2 Watchers
  • 2 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

AutoLockBuild StatusCode Coverage

AutoLock - Redis distributed locks in PHP, (*1)

This library implements the RedLock algorithm introduced by @antirez, (*2)

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

To create a lock manager:, (*4)


$pool = new \AutoLock\Pool(array( '192.168.1.1:6379', '192.168.1.2:6379', '192.168.1.3:6379', ),new \AutoLock\Drivers\PHPRedis()); $manager = new \AutoLock\Manager($pool);

To acquire a lock:, (*5)


$lock = $manager->lock('distributed_lock',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 object representing the lock is returned, you should use isExpired method to detect whether the lock is expired now or in certain time:, (*7)


$status = $lock->isExpired(); //$status will be true if the lock is expired or it will be false $status = $lock->isExpired(3600 * 1000); //$status will be true if the lock will be expired after 3600 seconds or it will be false
  • 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)

    $lock->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)

The Versions

23/11 2017

dev-master

9999999-dev

Redis distributed locks in PHP

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0
  • ext-redis ^2.2.5|^3.0.0

 

The Development Requires

by liulu

redis lock redlock

23/11 2017

dev-mmdtl-patch-1

dev-mmdtl-patch-1

Redis distributed locks in PHP

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0
  • ext-redis ^2.2.5|^3.0.0

 

The Development Requires

by liulu

redis lock redlock

28/03 2017

0.1.0

0.1.0.0

Redis distributed locks in PHP

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0
  • ext-redis ^2.2.5|^3.0.0

 

The Development Requires

by liulu

redis lock redlock