{"id":"0abf1e4e41d01412","repo":"redis/redis-py","slug":"argument-db-is-not-possible-to-use-in-cluster-mo","errorCode":null,"errorMessage":"Argument 'db' is not possible to use in cluster mode","messagePattern":"Argument 'db' is not possible to use in cluster mode","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":817,"sourceCode":"            If not provided and protocol is RESP3, the maintenance notifications\n            will be enabled by default (logic is included in the NodesManager\n            initialization).\n        :**kwargs:\n            Extra arguments that will be sent into Redis instance when created\n            (See Official redis-py doc for supported kwargs - the only limitation\n            is that you can't provide 'retry' object as part of kwargs.\n            [https://github.com/andymccurdy/redis-py/blob/master/redis/client.py])\n            Some kwargs are not supported and will raise a\n            RedisClusterException:\n                - db (Redis do not support database SELECT in cluster mode)\n\n        \"\"\"\n        if startup_nodes is None:\n            startup_nodes = []\n\n        if \"db\" in kwargs:\n            # Argument 'db' is not possible to use in cluster mode\n            raise RedisClusterException(\n                \"Argument 'db' is not possible to use in cluster mode\"\n            )\n\n        if \"retry\" in kwargs:\n            # Argument 'retry' is not possible to be used in kwargs when in cluster mode\n            # the kwargs are set to the lower level connections to the cluster nodes\n            # 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:","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L799-L835","documentation":"Raised in `RedisCluster.__init__` when the user passes `db=<n>` as a keyword argument. Redis Cluster does not support the SELECT command (all keys are partitioned across the 16384 slot space and there is a single logical keyspace), so any non-zero — in fact any — `db` kwarg is rejected with RedisClusterException to prevent silent misuse.","triggerScenarios":"Constructing `RedisCluster(host=..., port=..., db=1)` or passing `db` via connection kwargs to RedisCluster. The check `'db' in kwargs` triggers before any connection is made.","commonSituations":"Reusing standalone-Redis connection kwargs (where `db=0..15` is normal) when switching to RedisCluster; passing a shared config dict that includes `db`; URL-based configs that include a db index.","solutions":["Remove the `db` kwarg from the RedisCluster constructor call — cluster mode uses a single logical database.","If sharing a config dict, strip `db` for cluster clients: `{k:v for k,v in cfg.items() if k != 'db'}`.","For URLs, ensure the DSN has no `/db` path component (or use `/0`)."],"exampleFix":"# before\nrc = RedisCluster(host='localhost', port=7000, db=1)  # raises\n\n# after\nrc = RedisCluster(host='localhost', port=7000)","handlingStrategy":"validation","validationCode":"kwargs = {'host': 'h', 'port': 7000}\nassert 'db' not in kwargs, 'db is invalid for cluster mode'\nrc = RedisCluster(**kwargs)","typeGuard":"def cluster_kwargs_ok(kwargs: dict) -> bool:\n    return 'db' not in kwargs and 'retry' not in kwargs","tryCatchPattern":null,"preventionTips":["Never pass db to RedisCluster.","When sharing config, strip db for cluster clients."],"tags":["cluster","config","initialization"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}