Skip to content

Adding Sentinel Commands #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions redis/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,60 @@ def slave_for(self, service_name, redis_class=StrictRedis,
connection_kwargs.update(kwargs)
return redis_class(connection_pool=connection_pool_class(
service_name, self, **connection_kwargs))

def _execute_command(self, command):
"""
Execute Sentinel command in all sentinels nodes
"""
for sentinel in self.sentinels:
sentinel.execute_command('SENTINEL '.format(command))
return True

def sentinel_reset(self, patter):
"""
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.
"""
return self._execute_command('reset {}'.format(patter))

def sentinel_failover(self, new_master_name):
"""
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).
"""
return self._execute_command('failover {}'.format(new_master_name))

def sentinel_ckquorum(self, new_master_name):
"""
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.
"""
return self._execute_command('ckquorum {}'.format(new_master_name))

def sentinel_flushconfig(self):
"""
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 self._execute_command('flushconfig')