for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of ninja-mutex.
*
* (C) leo108 <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NinjaMutex\Lock;
use Redis;
* Lock implementor using PHPRedis
* @author leo108 <[email protected]>
class PhpRedisLock extends LockAbstract
{
* Redis connection
* @var
protected $client;
* @param $client Redis
public function __construct($client)
parent::__construct();
$this->client = $client;
}
* @param string $name
* @param bool $blocking
* @return bool
protected function getLock($name, $blocking)
if (!$this->client->setnx($name, serialize($this->getLockInformation()))) {
return false;
return true;
* Release lock
* @param string $name name of lock
public function releaseLock($name)
if (isset($this->locks[$name]) && $this->client->del($name)) {
unset($this->locks[$name]);
* Check if lock is locked
public function isLocked($name)
return false !== $this->client->get($name);