{"id":"8323187eadb07bb2","repo":"redis/redis-py","slug":"a-db-querystring-option-can-only-be-0-in-clust","errorCode":null,"errorMessage":"A ``db`` querystring option can only be 0 in cluster mode","messagePattern":"A ``db`` querystring option can only be 0 in cluster mode","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":842,"sourceCode":"            # and there we provide retry configuration without retries allowed.\n            # The retries should be handled on cluster client level.\n            raise RedisClusterException(\n                \"The 'retry' argument cannot be used in kwargs when running in cluster mode.\"\n            )\n\n        # Get the startup node/s\n        from_url = False\n        if url is not None:\n            from_url = True\n            url_options = parse_url(url)\n            if \"path\" in url_options:\n                raise RedisClusterException(\n                    \"RedisCluster does not currently support Unix Domain \"\n                    \"Socket connections\"\n                )\n            if \"db\" in url_options and url_options[\"db\"] != 0:\n                # Argument 'db' is not possible to use in cluster mode\n                raise RedisClusterException(\n                    \"A ``db`` querystring option can only be 0 in cluster mode\"\n                )\n            kwargs.update(url_options)\n            host = kwargs.get(\"host\")\n            port = kwargs.get(\"port\", port)\n            startup_nodes.append(ClusterNode(host, port))\n        elif host is not None and port is not None:\n            startup_nodes.append(ClusterNode(host, port))\n        elif len(startup_nodes) == 0:\n            # No startup node was provided\n            raise RedisClusterException(\n                \"RedisCluster requires at least one node to discover the \"\n                \"cluster. Please provide one of the followings:\\n\"\n                \"1. host and port, for example:\\n\"\n                \" RedisCluster(host='localhost', port=6379)\\n\"\n                \"2. list of startup nodes, for example:\\n\"\n                \" RedisCluster(startup_nodes=[ClusterNode('localhost', 6379),\"\n                \" ClusterNode('localhost', 6378)])\"","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L824-L860","documentation":"Raised in `RedisCluster.__init__` URL-handling branch when the parsed URL contains a `db` query/path option whose value is not 0. Since cluster mode has a single logical database and SELECT is unsupported, the only tolerated value is 0; any other index is rejected with RedisClusterException.","triggerScenarios":"Calling `RedisCluster.from_url('redis://host:7000/1')` or `RedisCluster(url='redis://...?db=2')`. The URL parser extracts `db` and the constructor checks `url_options['db'] != 0`.","commonSituations":"Porting a standalone Redis URL that uses `/2` for a logical database into a cluster client; templated config strings that always append a db index.","solutions":["Drop the db index from the cluster URL: `redis://host:7000` or `redis://host:7000/0`.","Adjust templating so cluster URLs omit the db segment.","If you need logical isolation in cluster mode, use key-prefix namespacing instead of db indexes."],"exampleFix":"# before\nrc = RedisCluster.from_url('redis://localhost:7000/1')  # raises\n\n# after\nrc = RedisCluster.from_url('redis://localhost:7000/0')","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nu = urlparse(url)\n# path like '/1' or query '?db=2'\ndb = u.path.strip('/') if u.path not in ('', '/') else '0'\nassert db in ('', '0'), 'db must be 0 in cluster mode'","typeGuard":"def cluster_url_db_ok(url: str) -> bool:\n    u = urlparse(url)\n    return u.path in ('', '/', '/0')","tryCatchPattern":null,"preventionTips":["Omit the db index from cluster URLs (or use /0).","Use key-prefix namespacing instead of db indexes in cluster mode."],"tags":["cluster","config","url","initialization"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}