PHP Класс malkusch\lock\mutex\RedisMutex

Note: If you're going to use this mutex in a forked process, you have to call {@link seedRandom()} in each instance.
Автор: Markus Malkusch ([email protected])
Наследование: extends SpinlockMutex, implements Psr\Log\LoggerAwareInterface
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( array $redisAPIs, string $name, integer $timeout = 3 ) Sets the Redis APIs.
seedRandom ( integer | null $seed = null ) Seeds the random number generator.
setLogger ( Psr\Log\LoggerInterface $logger ) Sets a logger instance on the object

Защищенные методы

Метод Описание
acquire ( $key, $expire )
add ( mixed $redisAPI, string $key, string $value, integer $expire ) : boolean Sets the key only if such key doesn't exist at the server yet.
evalScript ( mixed $redisAPI, string $script, integer $numkeys, array $arguments ) : mixed
getRedisIdentifier ( mixed $redisAPI ) : string Returns a string representation of the Redis API.
release ( $key )

Приватные методы

Метод Описание
isMajority ( integer $count ) : boolean Returns if a count is the majority of all servers.

Описание методов

__construct() публичный Метод

Sets the Redis APIs.
public __construct ( array $redisAPIs, string $name, integer $timeout = 3 )
$redisAPIs array The Redis APIs.
$name string The lock name.
$timeout integer The time in seconds a lock expires, default is 3.

acquire() защищенный Метод

protected acquire ( $key, $expire )

add() абстрактный защищенный Метод

Sets the key only if such key doesn't exist at the server yet.
abstract protected add ( mixed $redisAPI, string $key, string $value, integer $expire ) : boolean
$redisAPI mixed The connected Redis API.
$key string The key.
$value string The value.
$expire integer The TTL seconds.
Результат boolean True, if the key was set.

evalScript() абстрактный защищенный Метод

abstract protected evalScript ( mixed $redisAPI, string $script, integer $numkeys, array $arguments ) : mixed
$redisAPI mixed The connected Redis API.
$script string The Lua script.
$numkeys integer The number of arguments that represent Redis key names.
$arguments array Keys and values.
Результат mixed The script result, or false if executing failed.

getRedisIdentifier() абстрактный защищенный Метод

Returns a string representation of the Redis API.
abstract protected getRedisIdentifier ( mixed $redisAPI ) : string
$redisAPI mixed The connected Redis API.
Результат string The identifier.

release() защищенный Метод

protected release ( $key )

seedRandom() публичный Метод

Normally you don't need to seed, as this happens automatically. But if you experience a {@link LockReleaseException} this might come from identically created random tokens. In this case you could seed from /dev/urandom.
public seedRandom ( integer | null $seed = null )
$seed integer | null The optional seed.

setLogger() публичный Метод

RedLock is a fault tolerant lock algorithm. I.e. it does tolerate failing redis connections without breaking. If you want to get notified about such events you'll have to provide a logger. Those events will be logged as warnings.
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface The logger.