{"record":{"id":"69e98d615da30e90","repo":"redis/redis-py","slug":"slaveof-is-not-supported-in-cluster-mode","errorCode":null,"errorMessage":"SLAVEOF is not supported in cluster mode","messagePattern":"SLAVEOF is not supported in cluster mode","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/commands/cluster.py","lineNumber":458,"sourceCode":"        ]\n        return await pipe.execute()\n\n\nclass ClusterManagementCommands(ManagementCommands):\n    \"\"\"\n    A class for Redis Cluster management commands\n\n    The class inherits from Redis's core ManagementCommands class and do the\n    required adjustments to work with cluster mode\n    \"\"\"\n\n    def slaveof(self, *args, **kwargs) -> NoReturn:\n        \"\"\"\n        Make the server a replica of another instance, or promote it as master.\n\n        For more information see https://redis.io/commands/slaveof\n        \"\"\"\n        raise RedisClusterException(\"SLAVEOF is not supported in cluster mode\")\n\n    def replicaof(self, *args, **kwargs) -> NoReturn:\n        \"\"\"\n        Make the server a replica of another instance, or promote it as master.\n\n        For more information see https://redis.io/commands/replicaof\n        \"\"\"\n        raise RedisClusterException(\"REPLICAOF is not supported in cluster mode\")\n\n    def swapdb(self, *args, **kwargs) -> NoReturn:\n        \"\"\"\n        Swaps two Redis databases.\n\n        For more information see https://redis.io/commands/swapdb\n        \"\"\"\n        raise RedisClusterException(\"SWAPDB is not supported in cluster mode\")\n\n    @overload","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/cluster.py#L440-L476","documentation":"Raised by ClusterManagementCommands.slaveof() in redis/commands/cluster.py:458. SLAVEOF changes a node's replication master, but in Redis Cluster every node's slot ownership and replication topology are managed by the cluster, so the command is forbidden. The method is overridden purely to fail fast with a clear message instead of sending an invalid command.","triggerScenarios":"Calling rc.slaveof(...) on a RedisCluster client instance.","commonSituations":"Code shared between standalone and cluster deployments that unconditionally calls slaveof(); automation that reconfigures replication generically.","solutions":["Use CLUSTER subcommands (CLUSTER FAILOVER, CLUSTER REPLICATE) to manage cluster replication.","Branch on client type: only call slaveof() on a standalone redis.Redis client.","Prefer replicaof()/cluster_replicate() for newer Redis deployments."],"exampleFix":"// before\nrc.slaveof('newmaster', 6379)\n// after\nrc.cluster_replicate(target_node, master_node_id)","handlingStrategy":"type-guard","validationCode":"from redis.cluster import RedisCluster\nif not isinstance(rc, RedisCluster):\n    rc.slaveof(host, port)\nelse:\n    rc.cluster_replicate(target_node, master_node_id)","typeGuard":"from redis.cluster import RedisCluster\ndef is_cluster_client(client) -> bool:\n    return isinstance(client, RedisCluster)","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    rc.slaveof(host, port)\nexcept RedisClusterException:\n    rc.cluster_replicate(target_node, master_node_id)","preventionTips":["Branch replication calls on client type.","Prefer cluster_replicate() for cluster deployments."],"tags":["cluster","replication","api-misuse","unsupported-command"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}