Download the PHP package cheprasov/php-redis-lock without Composer
On this page you can find all versions of the php package cheprasov/php-redis-lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cheprasov/php-redis-lock
More information about cheprasov/php-redis-lock
Files in cheprasov/php-redis-lock
Package php-redis-lock
Short Description RedisLock for PHP is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy.
License MIT
Homepage http://github.com/cheprasov/php-redis-lock
Informations about the package php-redis-lock
RedisLock v1.0.3 for PHP >= 5.5
About
RedisLock for PHP is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy. Based on redis.
Usage
Create a new instance of RedisLock
Usage for lock a process
Methods
RedisLock :: __construct ( RedisClient
$Redis , string
$key [, int
$flags = 0 ] )
Create a new instance of RedisLock.
Method Pameters
- RedisClient $Redis - Instanse of RedisClient
- string $key - name of key in Redis storage. Only locks with the same name will compete with each other for lock.
- int $flags, default = 0
RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS
- use this flag, if you don't want catch exceptions by yourself. Do not use this flag, if you want have a full control on situation with locks. Default behavior without this flag - all Exceptions will be thrown.
Example
bool
RedisLock :: acquire ( int|float
$lockTime , [ float
$waitTime = 0 [, float
$sleep = 0.005 ] ] )
Try to acquire lock for $lockTime
seconds.
If lock has acquired in another thread then we will wait $waitTime
seconds, until another thread release the lock.
Otherwise method throws a exception (if FLAG_DO_NOT_THROW_EXCEPTIONS
is not set) or result.
Returns true
on success or false
on failure.
Method Pameters
- int|float $lockTime - The time for lock in seconds, the value must be
>= 0.01
. - float $waitTime, default = 0 - The time for waiting lock in seconds. Use
0
if you don't wait until lock release. - float $sleep, default = 0.005 - The wait time between iterations to check the availability of the lock.
Example
bool
RedisLock :: update ( int|float
$lockTime )
Set a new time for lock if it is acquired already. Returns true
on success or false
on failure. Method can throw Exceptions.
Method Pameters
- int|float $lockTime - Please, see description for method
RedisLock :: acquire
Example
bool
RedisLock :: isAcquired ( )
Check this lock for acquired. Returns true
on success or false
on failure.
bool
RedisLock :: isLocked ( )
Check this lock for acquired and not expired, and active yet. Returns true
on success or false
on failure. Method can throw Exceptions.
bool
RedisLock :: isExists ()
Does lock exists or acquired anywhere? Returns true
if lock is exists or false
if is not.
Installation
Composer
Download composer:
wget -nc http://getcomposer.org/composer.phar
and add dependency to your project:
php composer.phar require cheprasov/php-redis-lock
Running tests
To run tests type in console:
./vendor/bin/phpunit
Something doesn't work
Feel free to fork project, fix bugs and finally request for pull