RdbMultiMutex
in package
implements
MutexInterface
Table of Contents
Interfaces
- MutexInterface
- A locking mechanism.
Constants
- LUA_ACQUIRE : mixed = <<<LUA if redis.call("EXISTS", unpack(KEYS)) >...
- LUA_RELEASE : mixed = <<<LUA local values = redis.call("MGET", unpack...
Properties
- $autoExpire : int|float
- $autoRelease : bool
- $names : array<string|int, string>
- $prefix : string
- $rdb : Rdb
- $values : array<string|int, string>
Methods
- __construct() : mixed
- __destruct() : mixed
- acquire() : bool
- Acquire the lock.
- release() : bool
- Release the lock.
- resume() : bool
- Join with an existing mutex.
- generateValue() : string
- Generate a value for the mutex.
- getKeys() : array<string|int, string>
- Get the full key for this mutex.
- tryAcquire() : bool
- Try to acquire the mutex.
Constants
LUA_ACQUIRE
public
mixed
LUA_ACQUIRE
= <<<LUA
if redis.call("EXISTS", unpack(KEYS)) > 0 then
return false
end
for index, key in ipairs(KEYS) do
redis.call("SET", key, ARGV[index], "NX", "PX", ARGV[#ARGV])
end
return redis.call("MGET", unpack(KEYS))
LUA
LUA_RELEASE
public
mixed
LUA_RELEASE
= <<<LUA
local values = redis.call("MGET", unpack(KEYS))
local count = 0
for index, value in ipairs(values) do
if value == ARGV[index] then
count = count + redis.call("DEL", KEYS[index])
end
end
return count
LUA
Properties
$autoExpire
public
int|float
$autoExpire
= 60
in seconds, 0 for infinite
$autoRelease
public
bool
$autoRelease
= true
$names
public
array<string|int, string>
$names
$prefix
public
string
$prefix
= 'mutex:'
$rdb
public
Rdb
$rdb
$values
protected
array<string|int, string>
$values
= []
Methods
__construct()
public
__construct(Rdb $rdb, array<string|int, string> $names) : mixed
Parameters
- $rdb : Rdb
- $names : array<string|int, string>
__destruct()
public
__destruct() : mixed
Tags
acquire()
Acquire the lock.
public
acquire([float $timeout = 0 ]) : bool
Parameters
- $timeout : float = 0
-
in seconds
Tags
Return values
boolrelease()
Release the lock.
public
release() : bool
Tags
Return values
boolresume()
Join with an existing mutex.
public
resume() : bool
Return values
bool —if successful and locked, otherwise unlocked.
generateValue()
Generate a value for the mutex.
protected
generateValue() : string
Return values
stringgetKeys()
Get the full key for this mutex.
protected
getKeys() : array<string|int, string>
Return values
array<string|int, string>tryAcquire()
Try to acquire the mutex.
protected
tryAcquire() : bool