Redis Sentinel Commands

redis-py can be used together with Redis Sentinel to discover Redis nodes. You need to have at least one Sentinel daemon running in order to use redis-py’s Sentinel support.

Connection example (assumes redis redis on the ports listed below):

>>> from redis import Sentinel
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
>>> sentinel.discover_master('mymaster')
('127.0.0.1', 6379)
>>> sentinel.discover_slaves('mymaster')
[('127.0.0.1', 6380)]
class redis.commands.sentinel.SentinelCommands[source]

A class containing the commands specific to redis sentinal. This class is to be used as a mixin.

sentinel(*args)[source]

Redis Sentinel’s SENTINEL command.

sentinel_ckquorum(new_master_name)[source]

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.

sentinel_failover(new_master_name)[source]

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

sentinel_flushconfig()[source]

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.

sentinel_get_master_addr_by_name(service_name)[source]

Returns a (host, port) pair for the given service_name

sentinel_master(service_name)[source]

Returns a dictionary containing the specified masters state.

sentinel_masters()[source]

Returns a list of dictionaries containing each master’s state.

sentinel_monitor(name, ip, port, quorum)[source]

Add a new master to Sentinel to be monitored

sentinel_remove(name)[source]

Remove a master from Sentinel’s monitoring

sentinel_reset(pattern)[source]

This command will 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 slave and sentinel already discovered and associated with the master.

sentinel_sentinels(service_name)[source]

Returns a list of sentinels for service_name

sentinel_set(name, option, value)[source]

Set Sentinel monitoring parameters for a given master

sentinel_slaves(service_name)[source]

Returns a list of slaves for service_name