MasterSlaveReplication
in package
implements
ReplicationInterface
Aggregate connection handling replication of Redis nodes configured in a single master / multiple slaves setup.
Tags
Interfaces, Classes and Traits
- ReplicationInterface
- Defines a group of Redis nodes in a master / slave replication setup.
Table of Contents
- $autoDiscovery : bool
- $connectionFactory : FactoryInterface
- $current : NodeConnectionInterface
- $master : NodeConnectionInterface
- $slaves : array<string|int, NodeConnectionInterface>
- $strategy : ReplicationStrategy
- __construct() : mixed
- {@inheritdoc}
- __sleep() : mixed
- {@inheritdoc}
- add() : mixed
- {@inheritdoc}
- connect() : mixed
- {@inheritdoc}
- disconnect() : mixed
- {@inheritdoc}
- discover() : mixed
- Fetches the replication configuration from one of the servers.
- executeCommand() : mixed
- {@inheritdoc}
- getConnection() : mixed
- {@inheritdoc}
- getConnectionById() : mixed
- {@inheritdoc}
- getCurrent() : NodeConnectionInterface
- Returns the connection instance currently in use by the aggregate connection.
- getMaster() : NodeConnectionInterface
- Returns the connection instance for the master Redis node.
- getReplicationStrategy() : ReplicationStrategy
- Returns the underlying replication strategy.
- getSlaves() : NodeConnectionInterface
- Returns a list of connection instances to slave nodes.
- isConnected() : mixed
- {@inheritdoc}
- readResponse() : mixed
- {@inheritdoc}
- remove() : mixed
- {@inheritdoc}
- setAutoDiscovery() : mixed
- Configures the automatic discovery of the replication configuration on failure.
- setConnectionFactory() : mixed
- Sets the connection factory used to create the connections by the auto discovery procedure.
- switchTo() : mixed
- Switches the internal connection instance in use.
- switchToMaster() : mixed
- Switches to the master server.
- switchToSlave() : mixed
- Switches to a random slave server.
- writeRequest() : mixed
- {@inheritdoc}
- discoverFromMaster() : mixed
- Discovers the replication configuration by contacting the master node.
- discoverFromSlave() : mixed
- Discovers the replication configuration by contacting one of the slaves.
- pickSlave() : NodeConnectionInterface
- Returns a random slave.
- reset() : mixed
- Resets the connection state.
- getMasterOrDie() : NodeConnectionInterface
- Returns the connection associated to the master server.
- handleInfoResponse() : array<string|int, mixed>
- Handles response from INFO.
- retryCommandOnFailure() : mixed
- Retries the execution of a command upon slave failure.
Properties
$autoDiscovery
protected
bool
$autoDiscovery
= false
$connectionFactory
protected
FactoryInterface
$connectionFactory
$current
protected
NodeConnectionInterface
$current
$master
protected
NodeConnectionInterface
$master
$slaves
protected
array<string|int, NodeConnectionInterface>
$slaves
= array()
$strategy
protected
ReplicationStrategy
$strategy
Methods
__construct()
{@inheritdoc}
public
__construct([ReplicationStrategy $strategy = null ]) : mixed
Parameters
- $strategy : ReplicationStrategy = null
Return values
mixed —__sleep()
{@inheritdoc}
public
__sleep() : mixed
Return values
mixed —add()
{@inheritdoc}
public
add(NodeConnectionInterface $connection) : mixed
Parameters
- $connection : NodeConnectionInterface
Return values
mixed —connect()
{@inheritdoc}
public
connect() : mixed
Return values
mixed —disconnect()
{@inheritdoc}
public
disconnect() : mixed
Return values
mixed —discover()
Fetches the replication configuration from one of the servers.
public
discover() : mixed
Return values
mixed —executeCommand()
{@inheritdoc}
public
executeCommand(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
Return values
mixed —getConnection()
{@inheritdoc}
public
getConnection(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
Return values
mixed —getConnectionById()
{@inheritdoc}
public
getConnectionById(mixed $connectionId) : mixed
Parameters
- $connectionId : mixed
Return values
mixed —getCurrent()
Returns the connection instance currently in use by the aggregate connection.
public
getCurrent() : NodeConnectionInterface
Return values
NodeConnectionInterface —getMaster()
Returns the connection instance for the master Redis node.
public
getMaster() : NodeConnectionInterface
Return values
NodeConnectionInterface —getReplicationStrategy()
Returns the underlying replication strategy.
public
getReplicationStrategy() : ReplicationStrategy
Return values
ReplicationStrategy —getSlaves()
Returns a list of connection instances to slave nodes.
public
getSlaves() : NodeConnectionInterface
Return values
NodeConnectionInterface —isConnected()
{@inheritdoc}
public
isConnected() : mixed
Return values
mixed —readResponse()
{@inheritdoc}
public
readResponse(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
Return values
mixed —remove()
{@inheritdoc}
public
remove(NodeConnectionInterface $connection) : mixed
Parameters
- $connection : NodeConnectionInterface
Return values
mixed —setAutoDiscovery()
Configures the automatic discovery of the replication configuration on failure.
public
setAutoDiscovery(bool $value) : mixed
Parameters
- $value : bool
-
Enable or disable auto discovery.
Return values
mixed —setConnectionFactory()
Sets the connection factory used to create the connections by the auto discovery procedure.
public
setConnectionFactory(FactoryInterface $connectionFactory) : mixed
Parameters
- $connectionFactory : FactoryInterface
-
Connection factory instance.
Return values
mixed —switchTo()
Switches the internal connection instance in use.
public
switchTo(mixed $connection) : mixed
Parameters
- $connection : mixed
-
Alias of a connection
Return values
mixed —switchToMaster()
Switches to the master server.
public
switchToMaster() : mixed
Return values
mixed —switchToSlave()
Switches to a random slave server.
public
switchToSlave() : mixed
Return values
mixed —writeRequest()
{@inheritdoc}
public
writeRequest(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
Return values
mixed —discoverFromMaster()
Discovers the replication configuration by contacting the master node.
protected
discoverFromMaster(NodeConnectionInterface $connection, FactoryInterface $connectionFactory) : mixed
Parameters
- $connection : NodeConnectionInterface
-
Connection to the master node.
- $connectionFactory : FactoryInterface
-
Connection factory instance.
Return values
mixed —discoverFromSlave()
Discovers the replication configuration by contacting one of the slaves.
protected
discoverFromSlave(NodeConnectionInterface $connection, FactoryInterface $connectionFactory) : mixed
Parameters
- $connection : NodeConnectionInterface
-
Connection to one of the slaves.
- $connectionFactory : FactoryInterface
-
Connection factory instance.
Return values
mixed —pickSlave()
Returns a random slave.
protected
pickSlave() : NodeConnectionInterface
Return values
NodeConnectionInterface —reset()
Resets the connection state.
protected
reset() : mixed
Return values
mixed —getMasterOrDie()
Returns the connection associated to the master server.
private
getMasterOrDie() : NodeConnectionInterface
Return values
NodeConnectionInterface —handleInfoResponse()
Handles response from INFO.
private
handleInfoResponse(string $response) : array<string|int, mixed>
Parameters
- $response : string
Return values
array<string|int, mixed> —retryCommandOnFailure()
Retries the execution of a command upon slave failure.
private
retryCommandOnFailure(CommandInterface $command, string $method) : mixed
Parameters
- $command : CommandInterface
-
Command instance.
- $method : string
-
Actual method.