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
파일 보기 프로젝트 열기: malkusch/lock 1 사용 예제들

공개 메소드들

메소드 설명
__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.