PHP Class Predis\Connection\Aggregate\SentinelReplication

Author: Daniele Alessandri ([email protected])
Author: Ville Mattila ([email protected])
Inheritance: implements Predis\Connection\Aggregate\ReplicationInterface
Show file Open project: tillkruss/redis-object-cache

Protected Properties

Property Type Description
$connectionFactory ConnectionFactoryInterface
$current Predis\Connection\NodeConnectionInterface
$master Predis\Connection\NodeConnectionInterface
$retryLimit integer -1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
$retryWait integer Time to wait in milliseconds before fetching a new configuration from one of the sentinel servers.
$sentinelConnection Predis\Connection\NodeConnectionInterface
$sentinelTimeout float
$sentinels Predis\Connection\NodeConnectionInterface[]
$service string
$slaves Predis\Connection\NodeConnectionInterface[]
$strategy Predis\Replication\ReplicationStrategy
$updateSentinels boolean Flag for automatic fetching of available sentinels.

Public Methods

Method Description
__construct ( string $service, array $sentinels, ConnectionFactoryInterface $connectionFactory, ReplicationStrategy $strategy = null )
__sleep ( )
add ( Predis\Connection\NodeConnectionInterface $connection )
connect ( )
disconnect ( )
executeCommand ( Predis\Command\CommandInterface $command )
getConnection ( Predis\Command\CommandInterface $command )
getConnectionById ( $connectionId )
getCurrent ( )
getMaster ( )
getReplicationStrategy ( ) : ReplicationStrategy Returns the underlying replication strategy.
getSentinelConnection ( ) : Predis\Connection\NodeConnectionInterface Returns the current sentinel connection.
getSlaves ( )
isConnected ( )
querySentinel ( ) Fetches the details for the master and slave servers from a sentinel.
readResponse ( Predis\Command\CommandInterface $command )
remove ( Predis\Connection\NodeConnectionInterface $connection )
setRetryLimit ( integer $retry ) Sets the maximum number of retries for commands upon server failure.
setRetryWait ( float $seconds ) Sets the time to wait (in seconds) before fetching a new configuration from one of the sentinels.
setSentinelTimeout ( float $timeout ) Sets a default timeout for connections to sentinels.
setUpdateSentinels ( boolean $update ) Set automatic fetching of available sentinels.
switchTo ( $connection )
switchToMaster ( ) Switches to the master server.
switchToSlave ( ) Switches to a random slave server.
updateSentinels ( ) Fetches an updated list of sentinels from a sentinel.
writeRequest ( Predis\Command\CommandInterface $command )

Protected Methods

Method Description
assertConnectionRole ( Predis\Connection\NodeConnectionInterface $connection, string $role ) Asserts that the specified connection matches an expected role.
createSentinelConnection ( $parameters ) : Predis\Connection\NodeConnectionInterface Creates a new connection to a sentinel server.
pickSlave ( ) : Predis\Connection\NodeConnectionInterface Returns a random slave.
querySentinelForMaster ( Predis\Connection\NodeConnectionInterface $sentinel, string $service ) : array Fetches the details for the master server from a sentinel.
querySentinelForSlaves ( Predis\Connection\NodeConnectionInterface $sentinel, string $service ) : array Fetches the details for the slave servers from a sentinel.
reset ( ) Resets the current connection.
wipeServerList ( ) Wipes the current list of master and slaves nodes.

Private Methods

Method Description
getConnectionInternal ( Predis\Command\CommandInterface $command ) : Predis\Connection\NodeConnectionInterface Returns the connection instance in charge for the given command.
handleSentinelErrorResponse ( Predis\Connection\NodeConnectionInterface $sentinel, ErrorResponseInterface $error ) Handles error responses returned by redis-sentinel.
retryCommandOnFailure ( Predis\Command\CommandInterface $command, string $method ) : mixed Retries the execution of a command upon server failure after asking a new configuration to one of the sentinels.

Method Details

__construct() public method

public __construct ( string $service, array $sentinels, ConnectionFactoryInterface $connectionFactory, ReplicationStrategy $strategy = null )
$service string Name of the service for autodiscovery.
$sentinels array Sentinel servers connection parameters.
$connectionFactory ConnectionFactoryInterface Connection factory instance.
$strategy Predis\Replication\ReplicationStrategy Replication strategy instance.

__sleep() public method

public __sleep ( )

add() public method

public add ( Predis\Connection\NodeConnectionInterface $connection )
$connection Predis\Connection\NodeConnectionInterface

assertConnectionRole() protected method

Asserts that the specified connection matches an expected role.
protected assertConnectionRole ( Predis\Connection\NodeConnectionInterface $connection, string $role )
$connection Predis\Connection\NodeConnectionInterface
$role string Expected role of the server ("master", "slave" or "sentinel").

connect() public method

public connect ( )

createSentinelConnection() protected method

Creates a new connection to a sentinel server.
protected createSentinelConnection ( $parameters ) : Predis\Connection\NodeConnectionInterface
return Predis\Connection\NodeConnectionInterface

disconnect() public method

public disconnect ( )

executeCommand() public method

public executeCommand ( Predis\Command\CommandInterface $command )
$command Predis\Command\CommandInterface

getConnection() public method

public getConnection ( Predis\Command\CommandInterface $command )
$command Predis\Command\CommandInterface

getConnectionById() public method

public getConnectionById ( $connectionId )

getCurrent() public method

public getCurrent ( )

getMaster() public method

public getMaster ( )

getReplicationStrategy() public method

Returns the underlying replication strategy.
public getReplicationStrategy ( ) : ReplicationStrategy
return Predis\Replication\ReplicationStrategy

getSentinelConnection() public method

If there is no active sentinel connection, a new connection is created.
public getSentinelConnection ( ) : Predis\Connection\NodeConnectionInterface
return Predis\Connection\NodeConnectionInterface

getSlaves() public method

public getSlaves ( )

isConnected() public method

public isConnected ( )

pickSlave() protected method

Returns a random slave.
protected pickSlave ( ) : Predis\Connection\NodeConnectionInterface
return Predis\Connection\NodeConnectionInterface

querySentinel() public method

Fetches the details for the master and slave servers from a sentinel.
public querySentinel ( )

querySentinelForMaster() protected method

Fetches the details for the master server from a sentinel.
protected querySentinelForMaster ( Predis\Connection\NodeConnectionInterface $sentinel, string $service ) : array
$sentinel Predis\Connection\NodeConnectionInterface Connection to a sentinel server.
$service string Name of the service.
return array

querySentinelForSlaves() protected method

Fetches the details for the slave servers from a sentinel.
protected querySentinelForSlaves ( Predis\Connection\NodeConnectionInterface $sentinel, string $service ) : array
$sentinel Predis\Connection\NodeConnectionInterface Connection to a sentinel server.
$service string Name of the service.
return array

readResponse() public method

public readResponse ( Predis\Command\CommandInterface $command )
$command Predis\Command\CommandInterface

remove() public method

public remove ( Predis\Connection\NodeConnectionInterface $connection )
$connection Predis\Connection\NodeConnectionInterface

reset() protected method

Resets the current connection.
protected reset ( )

setRetryLimit() public method

-1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
public setRetryLimit ( integer $retry )
$retry integer Number of retry attempts.

setRetryWait() public method

Sets the time to wait (in seconds) before fetching a new configuration from one of the sentinels.
public setRetryWait ( float $seconds )
$seconds float Time to wait before the next attempt.

setSentinelTimeout() public method

When "timeout" is present in the connection parameters of sentinels, its value overrides the default sentinel timeout.
public setSentinelTimeout ( float $timeout )
$timeout float Timeout value.

setUpdateSentinels() public method

Set automatic fetching of available sentinels.
public setUpdateSentinels ( boolean $update )
$update boolean Enable or disable automatic updates.

switchTo() public method

public switchTo ( $connection )

switchToMaster() public method

Switches to the master server.
public switchToMaster ( )

switchToSlave() public method

Switches to a random slave server.
public switchToSlave ( )

updateSentinels() public method

Fetches an updated list of sentinels from a sentinel.
public updateSentinels ( )

wipeServerList() protected method

Wipes the current list of master and slaves nodes.
protected wipeServerList ( )

writeRequest() public method

public writeRequest ( Predis\Command\CommandInterface $command )
$command Predis\Command\CommandInterface

Property Details

$connectionFactory protected property

protected ConnectionFactoryInterface $connectionFactory
return ConnectionFactoryInterface

$current protected property

protected NodeConnectionInterface,Predis\Connection $current
return Predis\Connection\NodeConnectionInterface

$master protected property

protected NodeConnectionInterface,Predis\Connection $master
return Predis\Connection\NodeConnectionInterface

$retryLimit protected property

-1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
protected int $retryLimit
return integer

$retryWait protected property

Time to wait in milliseconds before fetching a new configuration from one of the sentinel servers.
protected int $retryWait
return integer

$sentinelConnection protected property

protected NodeConnectionInterface,Predis\Connection $sentinelConnection
return Predis\Connection\NodeConnectionInterface

$sentinelTimeout protected property

protected float $sentinelTimeout
return float

$sentinels protected property

protected NodeConnectionInterface[],Predis\Connection $sentinels
return Predis\Connection\NodeConnectionInterface[]

$service protected property

protected string $service
return string

$slaves protected property

protected NodeConnectionInterface[],Predis\Connection $slaves
return Predis\Connection\NodeConnectionInterface[]

$strategy protected property

protected ReplicationStrategy,Predis\Replication $strategy
return Predis\Replication\ReplicationStrategy

$updateSentinels protected property

Flag for automatic fetching of available sentinels.
protected bool $updateSentinels
return boolean