class RedisSentinel (View source)

Helper autocomplete for phpredis extension

Methods

__construct(array|string|null $options_or_host = null, int $port = 26379, float $timeout = 0.0, string|null $persistent = null, int $retryInterval = 0, float $readTimeout = 0.0)

Creates a Redis Sentinel

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.

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

flushconfig()

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

RedisSentinel|array|bool
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.

RedisSentinel|array|bool
master(string $master)

Return the state and info of the specified master

RedisSentinel|array|bool
masters()

Return a list of monitored masters and their state

string
myid()

Return the run ID of this Sentinel instance.

ping()

Ping the sentinel

reset(string $pattern)

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

RedisSentinel|array|bool
sentinels(string $master)

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

RedisSentinel|array|bool
slaves(string $master)

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

Details

__construct(array|string|null $options_or_host = null, int $port = 26379, float $timeout = 0.0, string|null $persistent = null, int $retryInterval = 0, float $readTimeout = 0.0)

Creates a Redis Sentinel

You can either pass an array of options (recommended >= 6.0.0) or separate parameters (legacy).

Available options for array:

  • '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|string|null $options_or_host

Associative array of options, or Sentinel IP address/hostname

int $port

Sentinel Port (ignored if $options_or_host is an array)

float $timeout

Value in seconds (optional, default is 0 meaning unlimited)

string|null $persistent

Persistent connection id (optional, default is null meaning not persistent)

int $retryInterval

Value in milliseconds (optional, default is 0)

float $readTimeout

Value in seconds (optional, default is 0 meaning unlimited)

Examples

$sentinel = new RedisSentinel(['host' => '127.0.0.1']); // Default parameters (>= 6.0.0)
$sentinel = new RedisSentinel('127.0.0.1', 26379, 1, null, 100); // Legacy format

RedisSentinel|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.

Parameters

string $master

Return Value

RedisSentinel|bool

RedisSentinel|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).

Parameters

string $master

Return Value

RedisSentinel|bool

RedisSentinel|bool flushconfig()

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

RedisSentinel|bool

RedisSentinel|array|bool 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.

Parameters

string $master

Return Value

RedisSentinel|array|bool

RedisSentinel|array|bool master(string $master)

Return the state and info of the specified master

Parameters

string $master

Return Value

RedisSentinel|array|bool

RedisSentinel|array|bool masters()

Return a list of monitored masters and their state

Return Value

RedisSentinel|array|bool

string myid()

Return the run ID of this Sentinel instance.

Return Value

string

RedisSentinel|bool ping()

Ping the sentinel

Return Value

RedisSentinel|bool

RedisSentinel|int reset(string $pattern)

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

Return Value

RedisSentinel|int

RedisSentinel|array|bool sentinels(string $master)

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

Parameters

string $master

Return Value

RedisSentinel|array|bool

RedisSentinel|array|bool slaves(string $master)

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

Parameters

string $master

Return Value

RedisSentinel|array|bool