redis/redis-py · error · SlaveNotFoundError

No slave found for {self.service_name!r}

Error message

No slave found for {self.service_name!r}

What it means

Raised by SentinelConnectionPoolProxy.rotate_slaves (redis/sentinel.py:144) as redis.exceptions.SlaveNotFoundError (a ConnectionError subclass). When building a replica connection, the pool round-robins through discovered replicas; if none can be connected to, it falls back to the master address via get_master_address(). If that fallback also raises MasterNotFoundError, the loop exits and SlaveNotFoundError is raised with the service name.

Source

Thrown at redis/sentinel.py:144

            if connection_pool is not None:
                connection_pool.disconnect(inuse_connections=False)
        return master_address

    def rotate_slaves(self):
        slaves = self.sentinel_manager.discover_slaves(self.service_name)
        if slaves:
            if self.slave_rr_counter is None:
                self.slave_rr_counter = random.randint(0, len(slaves) - 1)
            for _ in range(len(slaves)):
                self.slave_rr_counter = (self.slave_rr_counter + 1) % len(slaves)
                slave = slaves[self.slave_rr_counter]
                yield slave
        # Fallback to the master connection
        try:
            yield self.get_master_address()
        except MasterNotFoundError:
            pass
        raise SlaveNotFoundError(f"No slave found for {self.service_name!r}")

    def rotate_replicas(self):
        """Round-robin replica balancer.

        This is an alias for :py:meth:`rotate_slaves`,
        using the preferred Redis 5.0+ terminology.
        """
        return self.rotate_slaves()


class SentinelConnectionPool(ConnectionPool):
    """
    Sentinel backed connection pool.

    If ``check_connection`` flag is set to True, SentinelManagedConnection
    sends a PING command right after establishing the connection.
    """

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Verify replica health from a Sentinel: redis-cli -p <sentinel_port> sentinel replicas <service_name>.
  2. Fall back to master_for(...) for reads when replicas are unavailable (read-your-writes permitting).
  3. Confirm Sentinel quorum is healthy and that Sentinels can see replicas.
  4. Check network connectivity / firewall rules between the client and replica ports.

Example fix

# before
reader = sentinel.slave_for('mymaster')
data = reader.get('k')
# after
from redis.sentinel import SlaveNotFoundError
from redis.exceptions import ConnectionError
try:
    reader = sentinel.slave_for('mymaster')
    data = reader.get('k')
except (SlaveNotFoundError, ConnectionError):
    reader = sentinel.master_for('mymaster')
    data = reader.get('k')
Defensive patterns

Strategy: fallback

Validate before calling

def replicas_available(sentinel, service_name: str) -> bool:
    return len(sentinel.discover_slaves(service_name)) > 0

# Choose reader based on availability
reader = (sentinel.slave_for(name) if replicas_available(sentinel, name)
          else sentinel.master_for(name))

Try / catch

from redis.sentinel import SlaveNotFoundError
from redis.exceptions import ConnectionError as RedisConnectionError

try:
    reader = sentinel.slave_for('mymaster')
    data = reader.get('k')
except (SlaveNotFoundError, RedisConnectionError):
    # Fall back to master for reads when replicas are unavailable
    reader = sentinel.master_for('mymaster')
    data = reader.get('k')

Prevention

When it happens

Trigger: Calling commands through a connection obtained via Sentinel.slave_for(...) / Sentinel.replica_for(...) when discover_slaves() returns an empty list or every discovered replica is unreachable (filter_slaves removed them, or connect_to raised ConnectionError for each), and the master fallback in rotate_slaves also fails (MasterNotFoundError caught at line 142).

Common situations: All replicas down or in ODOWN/SDOWN state; Sentinel has not yet learned the replica topology after a fresh deployment; network partition isolating the client from replicas but the master discovery path also failing; misconfigured service_name.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/b79e91718f8a3e33.json. Report an issue: GitHub.