{"id":"606c9d5f08a8d951","repo":"redis/redis-py","slug":"argument-db-must-be-0-or-none-in-cluster-mode","errorCode":null,"errorMessage":"Argument 'db' must be 0 or None in cluster mode","messagePattern":"Argument 'db' must be 0 or None in cluster mode","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":461,"sourceCode":"        ssl_ca_certs: str | None = None,\n        ssl_ca_data: str | None = None,\n        ssl_cert_reqs: \"str | VerifyMode\" = \"required\",\n        ssl_include_verify_flags: List[\"VerifyFlags\"] | None = None,\n        ssl_exclude_verify_flags: List[\"VerifyFlags\"] | None = None,\n        ssl_certfile: str | None = None,\n        ssl_check_hostname: bool = True,\n        ssl_keyfile: str | None = None,\n        ssl_min_version: \"TLSVersion | None\" = None,\n        ssl_ciphers: str | None = None,\n        protocol: int | None = None,\n        legacy_responses: bool = True,\n        address_remap: Callable[[Tuple[str, int]], Tuple[str, int]] | None = None,\n        event_dispatcher: EventDispatcher | None = None,\n        policy_resolver: AsyncPolicyResolver = AsyncStaticPolicyResolver(),\n        maint_notifications_config: MaintNotificationsConfig | None = None,\n    ) -> None:\n        if db:\n            raise RedisClusterException(\n                \"Argument 'db' must be 0 or None in cluster mode\"\n            )\n\n        if path:\n            raise RedisClusterException(\n                \"Unix domain socket is not supported in cluster mode\"\n            )\n\n        if (not host or not port) and not startup_nodes:\n            raise RedisClusterException(\n                \"RedisCluster requires at least one node to discover the cluster.\\n\"\n                \"Please provide one of the following or use RedisCluster.from_url:\\n\"\n                '   - host and port: RedisCluster(host=\"localhost\", port=6379)\\n'\n                \"   - startup_nodes: RedisCluster(startup_nodes=[\"\n                'ClusterNode(\"localhost\", 6379), ClusterNode(\"localhost\", 6380)])'\n            )\n\n        computed_driver_info = resolve_driver_info(driver_info, lib_name, lib_version)","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/cluster.py#L443-L479","documentation":"Raised by RedisCluster.__init__ (redis/asyncio/cluster.py:461) when a non-zero `db` argument is passed. Redis Cluster only supports database 0 (the CLUSTER subcommands and slot routing assume db 0), so selecting another db is invalid. The constructor rejects it immediately with RedisClusterException.","triggerScenarios":"Constructing RedisCluster(db=1, ...) or passing a URL like redis://host:6379/3 to a cluster client. The very first validation in __init__ checks `if db:`.","commonSituations":"Reusing a standalone-Redis config (which used db=N for logical separation) against a cluster endpoint; building RedisCluster from a shared settings object that carries a db field.","solutions":["Drop the db argument (defaults to 0) or set db=0 / db=None explicitly.","If you selected a db for namespace isolation, use key prefixes or separate clusters instead.","When constructing from a URL, ensure the path is /0 or absent: redis://host:port/0."],"exampleFix":"// before\nc = RedisCluster(host='localhost', port=16379, db=1)\n// after\nc = RedisCluster(host='localhost', port=16379)  # db defaults to None/0","handlingStrategy":"validation","validationCode":"if db not in (0, None):\n    raise ValueError('RedisCluster only supports db=0')\nc = RedisCluster(host=host, port=port, db=db)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass db != 0 to RedisCluster.","Strip/normalize the db field when sharing config between standalone and cluster clients.","Use key prefixes for logical separation in cluster mode."],"tags":["redis","asyncio","cluster","configuration","database-selection"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}