redis/redis-py · error · RedisClusterException

SLAVEOF is not supported in cluster mode

Error message

SLAVEOF is not supported in cluster mode

What it means

RedisClusterCommands.slaveof (redis/commands/cluster.py:452) unconditionally raises RedisClusterException. SLAVEOF reconfigures a single standalone Redis instance's replication role; in cluster mode replication is managed per-node via the cluster topology, so the command is disabled on the cluster client surface.

Source

Thrown at redis/commands/cluster.py:458

        ]
        return await pipe.execute()


class ClusterManagementCommands(ManagementCommands):
    """
    A class for Redis Cluster management commands

    The class inherits from Redis's core ManagementCommands class and do the
    required adjustments to work with cluster mode
    """

    def slaveof(self, *args, **kwargs) -> NoReturn:
        """
        Make the server a replica of another instance, or promote it as master.

        For more information see https://redis.io/commands/slaveof
        """
        raise RedisClusterException("SLAVEOF is not supported in cluster mode")

    def replicaof(self, *args, **kwargs) -> NoReturn:
        """
        Make the server a replica of another instance, or promote it as master.

        For more information see https://redis.io/commands/replicaof
        """
        raise RedisClusterException("REPLICAOF is not supported in cluster mode")

    def swapdb(self, *args, **kwargs) -> NoReturn:
        """
        Swaps two Redis databases.

        For more information see https://redis.io/commands/swapdb
        """
        raise RedisClusterException("SWAPDB is not supported in cluster mode")

    @overload

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Use the cluster-native failover command: rc.cluster_failover(target_node=<replica>, option='FORCE' or 'TAKEOVER').
  2. To change replication topology, use CLUSTER SETSLOT / redis-cli cluster management, not SLAVEOF.
  3. Run SLAVEOF against a non-cluster client connected to the specific node if you truly need standalone behavior on a node that is not part of the cluster.

Example fix

# before
rc.slaveof('otherhost', 6379)  # raises: SLAVEOF is not supported in cluster mode

# after
rc.cluster_failover(target_node=replica_node, option='FORCE')
Defensive patterns

Strategy: type-guard

Validate before calling

from redis.cluster import RedisCluster

def safe_replica_op(client, host=None, port=None):
    if isinstance(client, RedisCluster):
        raise ValueError('SLAVEOF is unsupported in cluster mode; use cluster_failover()')
    return client.slaveof(host, port)

Type guard

from redis.cluster import RedisCluster

def is_cluster_client(client) -> bool:
    return isinstance(client, RedisCluster)

Try / catch

from redis.exceptions import RedisClusterException

try:
    rc.slaveof('NO', 'ONE')
except RedisClusterException:
    rc.cluster_failover(target_node=replica, option='FORCE')

Prevention

When it happens

Trigger: Calling rc.slaveof(...) (or rc.slaveof('NO','ONE')) on a RedisCluster client. Any code path, including legacy cutover scripts, that invokes SLAVEOF against a cluster endpoint.

Common situations: Migrating failover/replication scripts from standalone redis to cluster. Old runbooks that promoted/demoted nodes with SLAVEOF. Confusing SLAVEOF (deprecated alias) with CLUSTER FAILOVER.

Related errors


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