Download the PHP package ginnerpeace/redlock-php without Composer
On this page you can find all versions of the php package ginnerpeace/redlock-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ginnerpeace/redlock-php
More information about ginnerpeace/redlock-php
Files in ginnerpeace/redlock-php
Package redlock-php
Short Description Redis distributed locks in PHP
License MIT
Homepage https://github.com/ginnerpeace/redlock-php
Informations about the package redlock-php
redlock-php - Redis distributed locks in PHP
Based on Redlock-php by Ronny López
Based on Redlock-rb by Salvatore Sanfilippo
This library implements the Redis-based distributed lock manager algorithm described in this blog post.
Install
Example
To create a lock manager
To acquire a lock
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, 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
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.