{"record":{"id":"da20cf7c0094bda5","repo":"redis/redis-py","slug":"node-host-port-doesn-t-exist-in-the-cluster","errorCode":null,"errorMessage":"Node {host}:{port} doesn't exist in the cluster","messagePattern":"Node (.+?):(.+?) doesn't exist in the cluster","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":3037,"sourceCode":"        else:\n            # nothing passed by the user. set node to None\n            pubsub_node = None\n\n        self.node = pubsub_node\n\n    def get_pubsub_node(self):\n        \"\"\"\n        Get the node that is being used as the pubsub connection\n        \"\"\"\n        return self.node\n\n    def _raise_on_invalid_node(self, redis_cluster, node, host, port):\n        \"\"\"\n        Raise a RedisClusterException if the node is None or doesn't exist in\n        the cluster.\n        \"\"\"\n        if node is None or redis_cluster.get_node(node_name=node.name) is None:\n            raise RedisClusterException(\n                f\"Node {host}:{port} doesn't exist in the cluster\"\n            )\n\n    def execute_command(self, *args):\n        \"\"\"\n        Execute a subscribe/unsubscribe command.\n\n        Taken code from redis-py and tweak to make it work within a cluster.\n        \"\"\"\n        # NOTE: don't parse the response in this function -- it could pull a\n        # legitimate message off the stack if the connection is already\n        # subscribed to one or more channels\n\n        if self.connection is None:\n            if self.connection_pool is None:\n                if len(args) > 1:\n                    # Hash the first channel and get one of the nodes holding\n                    # this slot","sourceCodeStart":3019,"sourceCodeEnd":3055,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L3019-L3055","documentation":"Raised as a RedisClusterException by _raise_on_invalid_node() (used by ClusterPubSub) when the provided node is None or is not found in the cluster's node cache (cluster.py:3036-3039). This means the host:port or ClusterNode passed to pubsub() does not correspond to any known node in the current topology.","triggerScenarios":"Calling client.pubsub(host=h, port=p) or client.pubsub(node=n) where h:p or n is not a member of the cluster (wrong address, typo, or a node that was removed). get_node() returns None or get_node(node_name=...) returns None.","commonSituations":"Using a stale host:port from before a cluster topology change, typo in address, or passing a ClusterNode from a different cluster instance.","solutions":["Verify the node exists: client.get_node(host, port) returns a ClusterNode before passing it to pubsub().","Use a known node from client.get_nodes() or client.get_primaries() instead of a hardcoded address.","If using a ClusterNode object, ensure it came from the same client instance's topology."],"exampleFix":"// before\nps = client.pubsub(host='10.0.0.99', port=7000)  # wrong address\n\n// after\nnodes = client.get_primaries()\nps = client.pubsub(node=nodes[0])","handlingStrategy":"validation","validationCode":"# Verify the node exists in the cluster before using it\nnode = client.get_node(host, port)\nif node is None:\n    raise ValueError(f'Node {host}:{port} is not in the cluster')\nps = client.pubsub(node=node)","typeGuard":"def node_exists_in_cluster(client, host, port) -> bool:\n    return client.get_node(host=host, port=port) is not None","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    ps = client.pubsub(host=h, port=p)\nexcept RedisClusterException as e:\n    if \"doesn't exist in the cluster\" in str(e):\n        ps = client.pubsub(node=client.get_primaries()[0])","preventionTips":["Use client.get_node(host, port) to confirm a node exists before passing it to pubsub().","Prefer passing ClusterNode objects from client.get_primaries()/get_nodes() over hardcoded addresses.","Refresh topology before using stale addresses after cluster changes."],"tags":["pubsub","node-not-found","validation","cluster"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}