class RedisSentinel (View source)

Helper autocomplete for phpredis extension

Methods

__construct(array $options)

Creates a Redis Sentinel

bool
ckquorum(string $master)

Check if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok.

bool
failover(string $master)

Force a failover as if the master was not reachable, and without asking for agreement to other Sentinels (however a new version of the configuration will be published so that the other Sentinels will update their configurations).

bool
flushconfig()

Force Sentinel to rewrite its configuration on disk, including the current Sentinel state.

array|false
getMasterAddrByName(string $master)

Return the ip and port number of the master with that name. If a failover is in progress or terminated successfully for this master it returns the address and port of the promoted replica.

array|false
master(string $master)

Return the state and info of the specified master

array|false
masters()

Return a list of monitored masters and their state

bool
ping()

Ping the sentinel

bool
reset(string $pattern)

Reset all the masters with matching name. The pattern argument is a glob-style pattern.

array|false
sentinels(string $master)

Return a list of sentinel instances for this master, and their state

array|false
slaves(string $master)

Return a list of sentinel instances for this master, and their state

Details

__construct(array $options)

Since: >= 6.0.0

Creates a Redis Sentinel

Accepts and array of options.

Available options:

  • 'host' => string, Sentinel IP address or hostname
  • 'port' => int, Sentinel Port (optional, default is 26379)
  • 'connectTimeout' => float, Value in seconds (optional, default is 0 meaning unlimited)
  • 'persistent' => string, Persistent connection id (optional, default is NULL meaning not persistent)
  • 'retryInterval' => int, Value in milliseconds (optional, default is 0)
  • 'readTimeout' => float, Value in seconds (optional, default is 0 meaning unlimited)
  • 'auth' => string|array, Authentication credentials (optional, default is NULL meaning NOAUTH)

Parameters

array $options

Associative array of options

Examples

$sentinel = new RedisSentinel(['host' => '127.0.0.1']); // default parameters

bool ckquorum(string $master)

Since: >= 5.2.0

Check if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok.

Parameters

string $master

Name of master

Return Value

bool

True in case of success, False in case of failure.

Examples

$sentinel->ckquorum('mymaster');

bool failover(string $master)

Since: >= 5.2.0

Force a failover as if the master was not reachable, and without asking for agreement to other Sentinels (however a new version of the configuration will be published so that the other Sentinels will update their configurations).

Parameters

string $master

Name of master

Return Value

bool

True in case of success, False in case of failure.

Examples

$sentinel->failover('mymaster');

bool flushconfig()

Since: >= 5.2.0

Force Sentinel to rewrite its configuration on disk, including the current Sentinel state.

Normally Sentinel rewrites the configuration every time something changes in its state (in the context of the subset of the state which is persisted on disk across restart). However sometimes it is possible that the configuration file is lost because of operation errors, disk failures, package upgrade scripts or configuration managers. In those cases a way to to force Sentinel to rewrite the configuration file is handy.

This command works even if the previous configuration file is completely missing.

Return Value

bool

True in case of success, False in case of failure.

Examples

$sentinel->flushconfig();

array|false getMasterAddrByName(string $master)

Since: >= 5.2.0

Return the ip and port number of the master with that name. If a failover is in progress or terminated successfully for this master it returns the address and port of the promoted replica.

Parameters

string $master

Name of master

Return Value

array|false

['address', 'port'] in case of success, False in case of failure.

Examples

$sentinel->getMasterAddrByName('mymaster');

array|false master(string $master)

Since: >= 5.2.0

Return the state and info of the specified master

Parameters

string $master

Name of master

Return Value

array|false

Associative array with info in case of success, False in case of failure.

Examples

$sentinel->master('mymaster');

array|false masters()

Since: >= 5.2.0

Return a list of monitored masters and their state

Return Value

array|false

Array of arrays with info for each master in case of success, FALSE in case of failure.

Examples

$sentinel->masters();

bool ping()

Since: >= 5.2.0

Ping the sentinel

Return Value

bool

True in case of success, False in case of failure

Examples

$sentinel->ping();

bool reset(string $pattern)

Since: >= 5.2.0

Reset all the masters with matching name. The pattern argument is a glob-style pattern.

The reset process clears any previous state in a master (including a failover in progress), and removes every replica and sentinel already discovered and associated with the master.

Parameters

string $pattern

Glob-style pattern

Return Value

bool

True in case of success, False in case of failure

Examples

$sentinel->reset('*');

array|false sentinels(string $master)

Since: >= 5.2.0

Return a list of sentinel instances for this master, and their state

Parameters

string $master

Name of master

Return Value

array|false

Array of arrays with info for each sentinel in case of success, False in case of failure

Examples

$sentinel->sentinels('mymaster');

array|false slaves(string $master)

Since: >= 5.2.0

Return a list of sentinel instances for this master, and their state

Parameters

string $master

Name of master

Return Value

array|false

Array of arrays with info for each replica in case of success, False in case of failure

Examples

$sentinel->slaves('mymaster');