{"record":{"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/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L799-L835","documentation":"Raised by RedisCluster.__init__ when 'db' is present in kwargs. Redis Cluster does not support SELECT — all keys are addressed by hash slot across nodes, so a logical database index is meaningless. The constructor rejects it eagerly to avoid silent misconfiguration.","triggerScenarios":"RedisCluster(host=..., port=..., db=1) or RedisCluster.from_url('redis://.../1') where the db leaks into kwargs (the from_url form is caught separately at 196). Direct kwarg use hits client.py-level guard at cluster.py:817.","commonSituations":"Copy-pasting a standalone Redis(...) config (with db=N) into a RedisCluster(...) call; environment-based config that injects db for all clients.","solutions":["Remove the db argument from your RedisCluster(...) call.","If loading config from a shared dict, strip/ignore the db key for cluster clients.","Remember cluster mode implies db 0 only; do not attempt to SELECT."],"exampleFix":"// before\nclient = RedisCluster(host='localhost', port=7000, db=1)  # RedisClusterException\n\n// after\nclient = RedisCluster(host='localhost', port=7000)","handlingStrategy":"validation","validationCode":"kwargs.pop('db', None)  # strip db before constructing cluster client\nclient = RedisCluster(host='localhost', port=7000, **kwargs)","typeGuard":"def kwargs_safe_for_cluster(kwargs) -> bool:\n    return 'db' not in kwargs","tryCatchPattern":"from redis.cluster import RedisClusterException\ntry:\n    client = RedisCluster(host='localhost', port=7000, db=db)\nexcept RedisClusterException:\n    client = RedisCluster(host='localhost', port=7000)","preventionTips":["Never pass db to a cluster client; cluster mode implies db 0.","When sharing config between standalone and cluster clients, strip db for the cluster path.","Centralize client construction in a factory that enforces cluster vs. standalone rules."],"tags":["cluster","config","api-misuse"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}