{"record":{"id":"49e403cc436d7f37","repo":"redis/redis-py","slug":"replicaof-is-not-supported-in-cluster-mode","errorCode":null,"errorMessage":"REPLICAOF is not supported in cluster mode","messagePattern":"REPLICAOF is not supported in cluster mode","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/commands/cluster.py","lineNumber":466,"sourceCode":"    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\n    def cluster_myid(\n        self: SyncClientProtocol, target_node: \"TargetNodesT\"\n    ) -> bytes | str: ...\n\n    @overload\n    def cluster_myid(\n        self: AsyncClientProtocol, target_node: \"TargetNodesT\"\n    ) -> Awaitable[bytes | str]: ...","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/cluster.py#L448-L484","documentation":"Raised by ClusterManagementCommands.replicaof() in redis/commands/cluster.py:466. REPLICAOF is the modern name for SLAVEOF; in cluster mode replication topology is cluster-managed, so the command is explicitly rejected to prevent corrupting the cluster.","triggerScenarios":"Calling rc.replicaof(...) on a RedisCluster client instance.","commonSituations":"Generic replication-management code applied to a cluster client; scripts that re-point replicas during failover without using cluster commands.","solutions":["Use CLUSTER REPLICATE / CLUSTER FAILOVER for cluster replication changes.","Guard the call so replicaof() is only invoked on standalone clients.","Operate on the node's config via redis-cli out of band if you truly need standalone behavior."],"exampleFix":"// before\nrc.replicaof('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.replicaof(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.replicaof(host, port)\nexcept RedisClusterException:\n    rc.cluster_replicate(target_node, master_node_id)","preventionTips":["Use cluster_replicate() in cluster deployments.","Guard generic replication code with a client-type check."],"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"}