SentinelReplication
in package
implements
ReplicationInterface
Tags
Interfaces, Classes and Traits
- ReplicationInterface
- Defines a group of Redis nodes in a master / slave replication setup.
Table of Contents
- $connectionFactory : FactoryInterface
- $current : NodeConnectionInterface
- $master : NodeConnectionInterface
- $retryLimit : int
- Max number of automatic retries of commands upon server failure.
- $retryWait : int
- Time to wait in milliseconds before fetching a new configuration from one of the sentinel servers.
- $sentinelConnection : NodeConnectionInterface
- $sentinels : array<string|int, NodeConnectionInterface>
- $sentinelTimeout : float
- $service : string
- $slaves : array<string|int, NodeConnectionInterface>
- $strategy : ReplicationStrategy
- $updateSentinels : bool
- Flag for automatic fetching of available sentinels.
- __construct() : mixed
- __sleep() : mixed
- {@inheritdoc}
- add() : mixed
- {@inheritdoc}
- connect() : mixed
- {@inheritdoc}
- disconnect() : mixed
- {@inheritdoc}
- 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.
- getSentinelConnection() : NodeConnectionInterface
- Returns the current sentinel connection.
- getSlaves() : NodeConnectionInterface
- Returns a list of connection instances to slave nodes.
- isConnected() : mixed
- {@inheritdoc}
- querySentinel() : mixed
- Fetches the details for the master and slave servers from a sentinel.
- readResponse() : mixed
- {@inheritdoc}
- remove() : mixed
- {@inheritdoc}
- setRetryLimit() : mixed
- Sets the maximum number of retries for commands upon server failure.
- setRetryWait() : mixed
- Sets the time to wait (in milliseconds) before fetching a new configuration from one of the sentinels.
- setSentinelTimeout() : mixed
- Sets a default timeout for connections to sentinels.
- setUpdateSentinels() : mixed
- Set automatic fetching of available sentinels.
- switchTo() : mixed
- Switches the internal connection instance in use.
- switchToMaster() : mixed
- Switches to the master server.
- switchToSlave() : mixed
- Switches to a random slave server.
- updateSentinels() : mixed
- Fetches an updated list of sentinels from a sentinel.
- writeRequest() : mixed
- {@inheritdoc}
- assertConnectionRole() : mixed
- Asserts that the specified connection matches an expected role.
- createSentinelConnection() : NodeConnectionInterface
- Creates a new connection to a sentinel server.
- pickSlave() : NodeConnectionInterface
- Returns a random slave.
- querySentinelForMaster() : array<string|int, mixed>
- Fetches the details for the master server from a sentinel.
- querySentinelForSlaves() : array<string|int, mixed>
- Fetches the details for the slave servers from a sentinel.
- reset() : mixed
- Resets the current connection.
- wipeServerList() : mixed
- Wipes the current list of master and slaves nodes.
- getConnectionInternal() : NodeConnectionInterface
- Returns the connection instance in charge for the given command.
- handleSentinelErrorResponse() : mixed
- Handles error responses returned by redis-sentinel.
- retryCommandOnFailure() : mixed
- Retries the execution of a command upon server failure after asking a new configuration to one of the sentinels.
Properties
$connectionFactory
protected
FactoryInterface
$connectionFactory
$current
protected
NodeConnectionInterface
$current
$master
protected
NodeConnectionInterface
$master
$retryLimit
Max number of automatic retries of commands upon server failure.
protected
int
$retryLimit
= 20
-1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
$retryWait
Time to wait in milliseconds before fetching a new configuration from one of the sentinel servers.
protected
int
$retryWait
= 1000
$sentinelConnection
protected
NodeConnectionInterface
$sentinelConnection
$sentinels
protected
array<string|int, NodeConnectionInterface>
$sentinels
= array()
$sentinelTimeout
protected
float
$sentinelTimeout
= 0.1
$service
protected
string
$service
$slaves
protected
array<string|int, NodeConnectionInterface>
$slaves
= array()
$strategy
protected
ReplicationStrategy
$strategy
$updateSentinels
Flag for automatic fetching of available sentinels.
protected
bool
$updateSentinels
= false
Methods
__construct()
public
__construct(string $service, array<string|int, mixed> $sentinels, FactoryInterface $connectionFactory[, ReplicationStrategy $strategy = null ]) : mixed
Parameters
- $service : string
-
Name of the service for autodiscovery.
- $sentinels : array<string|int, mixed>
-
Sentinel servers connection parameters.
- $connectionFactory : FactoryInterface
-
Connection factory instance.
- $strategy : ReplicationStrategy = null
-
Replication strategy instance.
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 —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 —getSentinelConnection()
Returns the current sentinel connection.
public
getSentinelConnection() : NodeConnectionInterface
If there is no active sentinel connection, a new connection is created.
Return values
NodeConnectionInterface —getSlaves()
Returns a list of connection instances to slave nodes.
public
getSlaves() : NodeConnectionInterface
Return values
NodeConnectionInterface —isConnected()
{@inheritdoc}
public
isConnected() : mixed
Return values
mixed —querySentinel()
Fetches the details for the master and slave servers from a sentinel.
public
querySentinel() : 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 —setRetryLimit()
Sets the maximum number of retries for commands upon server failure.
public
setRetryLimit(int $retry) : mixed
-1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
Parameters
- $retry : int
-
Number of retry attempts.
Return values
mixed —setRetryWait()
Sets the time to wait (in milliseconds) before fetching a new configuration from one of the sentinels.
public
setRetryWait(float $milliseconds) : mixed
Parameters
- $milliseconds : float
-
Time to wait before the next attempt.
Return values
mixed —setSentinelTimeout()
Sets a default timeout for connections to sentinels.
public
setSentinelTimeout(float $timeout) : mixed
When "timeout" is present in the connection parameters of sentinels, its value overrides the default sentinel timeout.
Parameters
- $timeout : float
-
Timeout value.
Return values
mixed —setUpdateSentinels()
Set automatic fetching of available sentinels.
public
setUpdateSentinels(bool $update) : mixed
Parameters
- $update : bool
-
Enable or disable automatic updates.
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 —updateSentinels()
Fetches an updated list of sentinels from a sentinel.
public
updateSentinels() : mixed
Return values
mixed —writeRequest()
{@inheritdoc}
public
writeRequest(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
Return values
mixed —assertConnectionRole()
Asserts that the specified connection matches an expected role.
protected
assertConnectionRole(NodeConnectionInterface $connection, string $role) : mixed
Parameters
- $connection : NodeConnectionInterface
-
Connection to a redis server.
- $role : string
-
Expected role of the server ("master", "slave" or "sentinel").
Tags
Return values
mixed —createSentinelConnection()
Creates a new connection to a sentinel server.
protected
createSentinelConnection(mixed $parameters) : NodeConnectionInterface
Parameters
- $parameters : mixed
Return values
NodeConnectionInterface —pickSlave()
Returns a random slave.
protected
pickSlave() : NodeConnectionInterface
Return values
NodeConnectionInterface —querySentinelForMaster()
Fetches the details for the master server from a sentinel.
protected
querySentinelForMaster(NodeConnectionInterface $sentinel, string $service) : array<string|int, mixed>
Parameters
- $sentinel : NodeConnectionInterface
-
Connection to a sentinel server.
- $service : string
-
Name of the service.
Return values
array<string|int, mixed> —querySentinelForSlaves()
Fetches the details for the slave servers from a sentinel.
protected
querySentinelForSlaves(NodeConnectionInterface $sentinel, string $service) : array<string|int, mixed>
Parameters
- $sentinel : NodeConnectionInterface
-
Connection to a sentinel server.
- $service : string
-
Name of the service.
Return values
array<string|int, mixed> —reset()
Resets the current connection.
protected
reset() : mixed
Return values
mixed —wipeServerList()
Wipes the current list of master and slaves nodes.
protected
wipeServerList() : mixed
Return values
mixed —getConnectionInternal()
Returns the connection instance in charge for the given command.
private
getConnectionInternal(CommandInterface $command) : NodeConnectionInterface
Parameters
- $command : CommandInterface
-
Command instance.
Return values
NodeConnectionInterface —handleSentinelErrorResponse()
Handles error responses returned by redis-sentinel.
private
handleSentinelErrorResponse(NodeConnectionInterface $sentinel, ErrorInterface $error) : mixed
Parameters
- $sentinel : NodeConnectionInterface
-
Connection to a sentinel server.
- $error : ErrorInterface
-
Error response.
Return values
mixed —retryCommandOnFailure()
Retries the execution of a command upon server failure after asking a new configuration to one of the sentinels.
private
retryCommandOnFailure(CommandInterface $command, string $method) : mixed
Parameters
- $command : CommandInterface
-
Command instance.
- $method : string
-
Actual method.