redis/redis-py · error · SlaveNotFoundError

No slave found for

Error message

No slave found for {self.service_name!r}

What it means

Raised by SentinelConnectionPoolProxy.rotate_slaves() (redis/sentinel.py:144) when no replica is available to serve reads. rotate_slaves() first calls discover_slaves(service_name); if that returns an empty list (no replicas configured, or all filtered out as ODOWN/SDOWN via filter_slaves), the generator falls back to the master via get_master_address(); if THAT also raises MasterNotFoundError, the loop ends and SlaveNotFoundError is raised. So the client found neither a healthy replica nor a usable master fallback.

Solutions

  1. Ensure at least one healthy replica exists for the service: check `redis-cli -p <sentinel_port> SENTINEL replicas <name>`.
  2. Confirm service_name matches a monitored master with replicas attached.
  3. During transient outages, catch SlaveNotFoundError and fall back to master_for() for reads or retry with backoff.
  4. Add replicas to the topology if read scaling is required.

Example fix

# before: read client fails when no replica is reachable
slave = sentinel.slave_for('mymaster')
slave.get('k')  # SlaveNotFoundError: No slave found for 'mymaster'

# after: fall back to the master for reads when no replica is available
try:
    slave.get('k')
except redis.exceptions.SlaveNotFoundError:
    sentinel.master_for('mymaster').get('k')
Defensive patterns

Strategy: fallback

Validate before calling

def replicas_available(sentinel, service_name) -> bool:
    # call before routing a read to a replica
    return len(sentinel.discover_slaves(service_name)) > 0

# if not replicas_available(sentinel, 'mymaster'): route read to master_for(...)

Try / catch

import redis.exceptions

def read_with_replica_fallback(slave_client, master_client, op, *args, **kw):
    try:
        return op(slave_client, *args, **kw)
    except redis.exceptions.SlaveNotFoundError:
        # no replica available; degrade to master for this read
        return op(master_client, *args, **kw)

# usage:
# read_with_replica_fallback(slave, master, lambda c, k: c.get(k), 'k')

Prevention

When it happens

Trigger: Using slave_for(service_name) (read-only replica routing), the read connection pool calls rotate_slaves() to pick a replica; discover_slaves() yields nothing; the master fallback at sentinel.py:141 raises MasterNotFoundError (caught at 142); execution falls through to `raise SlaveNotFoundError(f"No slave found for {self.service_name!r}")`.

Common situations: Single-node Sentinel deployment with no replicas configured; all replicas simultaneously down or in SDOWN/ODOWN; during a failover where neither replicas nor a master is currently up; replicas exist but are all flagged subjectively down; service_name typo so discover_slaves returns [].

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/b79e91718f8a3e33. Report an issue: GitHub.

Appendix: 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 6a6b581b48)