PhpRedisLock.php
TLDR
This file defines the PhpRedisLock
class, which extends the RedisLock
class. It contains a constructor method and a release
method.
Methods
__construct
This method is the constructor of the PhpRedisLock
class. It takes in a PhpRedisConnection
instance, a string $name
, an integer $seconds
, and an optional string $owner
. It calls the constructor of the parent RedisLock
class with the provided arguments.
release
This method overrides the release
method of the parent RedisLock
class. It releases the lock by executing a Lua script using the eval
method of the PhpRedisConnection
. It returns a boolean indicating whether the lock was successfully released.
<?php
namespace Illuminate\Cache;
use Illuminate\Redis\Connections\PhpRedisConnection;
class PhpRedisLock extends RedisLock
{
/**
* Create a new phpredis lock instance.
*
* @param \Illuminate\Redis\Connections\PhpRedisConnection $redis
* @param string $name
* @param int $seconds
* @param string|null $owner
* @return void
*/
public function __construct(PhpRedisConnection $redis, string $name, int $seconds, ?string $owner = null)
{
parent::__construct($redis, $name, $seconds, $owner);
}
/**
* {@inheritDoc}
*/
public function release()
{
return (bool) $this->redis->eval(
LuaScripts::releaseLock(),
1,
$this->name,
...$this->redis->pack([$this->owner])
);
}
}