Skip to content

NeoVG/phpredis-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phpredis-lock

Simple mutex locking class with support for TTL using PHPRedis as backend.

Installation

composer require neovg/phpredis-lock

Setup

\NeoVg\PhpRedisLock\Lock::getInstance()->setConfig(
    (new \NeoVg\PhpRedisLock\ConfigStruct())
        ->withHost('127.0.0.1')
        ->withPort(6379)
        ->withDatabase(11)
);

Usage

Acquire and release

if (!\NeoVg\PhpRedisLock\Lock::getInstance()->acquire('name')) {
    echo 'could not acquire lock';
}

if (!\NeoVg\PhpRedisLock\Lock::getInstance()->release('name')) {
    echo 'could not release lock';
}

Non blocking acquire

\NeoVg\PhpRedisLock\Lock::getInstance()->acquire('name', 0);

Custom wait time (120 seconds)

\NeoVg\PhpRedisLock\Lock::getInstance()->acquire('name', 120);

TTL (60 seconds)

\NeoVg\PhpRedisLock\Lock::getInstance()->acquire('name', null, 60);

Check if already acquired (by this process)

\NeoVg\PhpRedisLock\Lock::getInstance()->isAcquired('name');

Check if already locked (by another process)

\NeoVg\PhpRedisLock\Lock::getInstance()->isLocked('name');

Get info about existing lock

$lockInfo = \NeoVg\PhpRedisLock\Lock::getInstance()->get('name;);

About

Simple mutex locking class with support for TTL using PHPRedis as backend

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages