PHP Class Predis\Connection\Aggregate\MasterSlaveReplication

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

Protected Properties

Property Type Description
$autoDiscovery boolean
$connectionFactory Predis\Connection\FactoryInterface
$current Predis\Connection\NodeConnectionInterface
$master Predis\Connection\NodeConnectionInterface
$slaves Predis\Connection\NodeConnectionInterface[]
$strategy Predis\Replication\ReplicationStrategy

Public Methods

Method Description
__construct ( ReplicationStrategy $strategy = null )
__sleep ( )
add ( Predis\Connection\NodeConnectionInterface $connection )
connect ( )
disconnect ( )
discover ( ) Fetches the replication configuration from one of the servers.
executeCommand ( Predis\Command\CommandInterface $command )
getConnection ( Predis\Command\CommandInterface $command )
getConnectionById ( $connectionId )
getCurrent ( )
getMaster ( )
getReplicationStrategy ( ) : ReplicationStrategy Returns the underlying replication strategy.
getSlaves ( )
isConnected ( )
readResponse ( Predis\Command\CommandInterface $command )
remove ( Predis\Connection\NodeConnectionInterface $connection )
setAutoDiscovery ( boolean $value ) Configures the automatic discovery of the replication configuration on failure.
setConnectionFactory ( Predis\Connection\FactoryInterface $connectionFactory ) Sets the connection factory used to create the connections by the auto discovery procedure.
switchTo ( $connection )
switchToMaster ( ) Switches to the master server.
switchToSlave ( ) Switches to a random slave server.
writeRequest ( Predis\Command\CommandInterface $command )

Protected Methods

Method Description
discoverFromMaster ( Predis\Connection\NodeConnectionInterface $connection, Predis\Connection\FactoryInterface $connectionFactory ) Discovers the replication configuration by contacting the master node.
discoverFromSlave ( Predis\Connection\NodeConnectionInterface $connection, Predis\Connection\FactoryInterface $connectionFactory ) Discovers the replication configuration by contacting one of the slaves.
pickSlave ( ) : Predis\Connection\NodeConnectionInterface Returns a random slave.
reset ( ) Resets the connection state.

Private Methods

Method Description
getMasterOrDie ( ) : Predis\Connection\NodeConnectionInterface Returns the connection associated to the master server.
handleInfoResponse ( string $response ) : array Handles response from INFO.
retryCommandOnFailure ( Predis\Command\CommandInterface $command, string $method ) : mixed Retries the execution of a command upon slave failure.

Method Details

__construct() public method

public __construct ( ReplicationStrategy $strategy = null )
$strategy Predis\Replication\ReplicationStrategy

__sleep() public method

public __sleep ( )

add() public method

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

connect() public method

public connect ( )

disconnect() public method

public disconnect ( )

discover() public method

Fetches the replication configuration from one of the servers.
public discover ( )

discoverFromMaster() protected method

Discovers the replication configuration by contacting the master node.
protected discoverFromMaster ( Predis\Connection\NodeConnectionInterface $connection, Predis\Connection\FactoryInterface $connectionFactory )
$connection Predis\Connection\NodeConnectionInterface Connection to the master node.
$connectionFactory Predis\Connection\FactoryInterface Connection factory instance.

discoverFromSlave() protected method

Discovers the replication configuration by contacting one of the slaves.
protected discoverFromSlave ( Predis\Connection\NodeConnectionInterface $connection, Predis\Connection\FactoryInterface $connectionFactory )
$connection Predis\Connection\NodeConnectionInterface Connection to one of the slaves.
$connectionFactory Predis\Connection\FactoryInterface Connection factory instance.

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

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

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 connection state.
protected reset ( )

setAutoDiscovery() public method

Configures the automatic discovery of the replication configuration on failure.
public setAutoDiscovery ( boolean $value )
$value boolean Enable or disable auto discovery.

setConnectionFactory() public method

Sets the connection factory used to create the connections by the auto discovery procedure.
public setConnectionFactory ( Predis\Connection\FactoryInterface $connectionFactory )
$connectionFactory Predis\Connection\FactoryInterface Connection factory instance.

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 ( )

writeRequest() public method

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

Property Details

$autoDiscovery protected property

protected bool $autoDiscovery
return boolean

$connectionFactory protected property

protected FactoryInterface,Predis\Connection $connectionFactory
return Predis\Connection\FactoryInterface

$current protected property

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

$master protected property

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

$slaves protected property

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

$strategy protected property

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