{"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/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/cluster.py#L448-L484","documentation":"RedisClusterCommands.replicaof (redis/commands/cluster.py:460) unconditionally raises. REPLICAOF is the non-deprecated successor to SLAVEOF for standalone redis; in cluster mode a node's replica role is governed by the cluster slot/replication config, so the command is not exposed on the cluster client.","triggerScenarios":"Calling rc.replicaof(...) (including rc.replicaof('NO','ONE')) on a RedisCluster client.","commonSituations":"Failover/demotion tooling written for standalone redis being pointed at a cluster. Scripts that call REPLICAOF NO ONE to promote a node during an incident. Renaming SLAVEOF to REPLICAOF in legacy code without changing the client type.","solutions":["Use CLUSTER FAILOVER for controlled replica-to-primary promotion: rc.cluster_failover(target_node=replica, option='FORCE').","Manage replication links through cluster admin tooling (redis-cli --cluster) rather than REPLICAOF.","If you must run REPLICAOF on one specific node, connect a non-cluster client to that single node."],"exampleFix":"# before\nrc.replicaof('newmaster', 6379)  # raises\n\n# after\nrc.cluster_failover(target_node=replica_node, option='TAKEOVER')","handlingStrategy":"type-guard","validationCode":"from redis.cluster import RedisCluster\n\ndef safe_replicaof(client, host=None, port=None):\n    if isinstance(client, RedisCluster):\n        raise ValueError('REPLICAOF is unsupported in cluster mode; use cluster_failover()')\n    return client.replicaof(host, port)","typeGuard":"from redis.cluster import RedisCluster\n\ndef is_cluster_client(client) -> bool:\n    return isinstance(client, RedisCluster)","tryCatchPattern":"from redis.exceptions import RedisClusterException\n\ntry:\n    rc.replicaof('NO', 'ONE')\nexcept RedisClusterException:\n    rc.cluster_failover(target_node=replica, option='FORCE')","preventionTips":["Prefer CLUSTER FAILOVER over REPLICAOF for cluster clients.","Branch shared code on whether the client is a RedisCluster instance.","Document that REPLICAOF is standalone-only in any cross-topology tooling."],"tags":["cluster","unsupported-command","replication"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}