def __init__(self, hosts, options): sentinel_kwargs = self._get_sentinel_kwargs(options) node_kwargs = self._get_node_kwargs(options) masters = None # Try to fetch a list of all masters from any sentinel. hosts = list(hosts) shuffle(hosts) # Randomly sort sentinels before trying to bootstrap. for host, port in hosts: client = StrictRedis(host=host, port=port, **sentinel_kwargs) try: masters = client.sentinel_masters().keys() break except RedisError: pass if masters is None: # No Sentinel responded successfully? raise errors.MastersListUnavailable if not len(masters): # The masters list was empty? raise errors.NoMastersConfigured sentinel_kwargs.update({ # Sentinels connected to fewer sentinels than `MIN_SENTINELS` will # be ignored. 'min_other_sentinels': options.get('MIN_SENTINELS', len(hosts) / 2), }) self.sentinel = Sentinel(hosts, **sentinel_kwargs) masters = [self.sentinel.master_for(name, **node_kwargs) for name in masters] super(SentinelBackedRingClient, self).__init__(masters, options)