diff options
Diffstat (limited to 'redis/sentinel.py')
-rw-r--r-- | redis/sentinel.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/redis/sentinel.py b/redis/sentinel.py index d321348..6456b8e 100644 --- a/redis/sentinel.py +++ b/redis/sentinel.py @@ -2,7 +2,7 @@ import random import weakref from redis.client import Redis -from redis.commands import SentinalCommands +from redis.commands import SentinelCommands from redis.connection import ConnectionPool, Connection from redis.exceptions import (ConnectionError, ResponseError, ReadOnlyError, TimeoutError) @@ -133,7 +133,7 @@ class SentinelConnectionPool(ConnectionPool): raise SlaveNotFoundError('No slave found for %r' % (self.service_name)) -class Sentinel(SentinalCommands, object): +class Sentinel(SentinelCommands, object): """ Redis Sentinel cluster client @@ -179,6 +179,23 @@ class Sentinel(SentinalCommands, object): self.min_other_sentinels = min_other_sentinels self.connection_kwargs = connection_kwargs + def execute_command(self, *args, **kwargs): + """ + Execute Sentinel command in sentinel nodes. + once - If set to True, then execute the resulting command on a single + node at random, rather than across the entire sentinel cluster. + """ + once = bool(kwargs.get('once', False)) + if 'once' in kwargs.keys(): + kwargs.pop('once') + + if once: + for sentinel in self.sentinels: + sentinel.execute_command(*args, **kwargs) + else: + random.choice(self.sentinels).execute_command(*args, **kwargs) + return True + def __repr__(self): sentinel_addresses = [] for sentinel in self.sentinels: |