Grokzen / redis-py-cluster

Python cluster client for the official redis cluster. Redis 3.0+.
https://redis-py-cluster.readthedocs.io/
MIT License
1.1k stars 315 forks source link

could I select the db ? #410

Closed ucasiggcas closed 4 years ago

ucasiggcas commented 4 years ago

hi,dear as I see the db in redis

help(redis.StrictRedis)
__init__(self, host='localhost', port=6379, db=0, password=None, socket_timeout=None, socket_connect_timeout=None, socket_keepalive=None, socket_keepalive_options=None, connection_pool=None, unix_socket_path=None, encoding='utf-8', encoding_errors='strict', charset=None, errors=None, decode_responses=False, retry_on_timeout=False, ssl=False, ssl_keyfile=None, ssl_certfile=None, ssl_cert_reqs='required', ssl_ca_certs=None, ssl_check_hostname=False, max_connections=None, single_connection_client=False, health_check_interval=0, client_name=None, username=None)

but in rediscluster can't find the parameter?

help(rediscluster.RedisCluster)
__init__(self, host=None, port=None, startup_nodes=None, max_connections=None, max_connections_per_node=False, 
init_slot_cache=True, readonly_mode=False, reinitialize_steps=None, skip_full_coverage_check=False, nodemanager_fol
low_cluster=False, connection_class=None, read_from_replicas=False, cluster_down_retry_attempts=3, host_port_remap=
None, **kwargs)

So could I set the parameter ?? thx

ucasiggcas commented 4 years ago
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/rediscluster/client.py", line 336, in __init__
    raise RedisClusterException("Argument 'db' is not possible to use in cluster mode")
rediscluster.exceptions.RedisClusterException: Argument 'db' is not possible to use in cluster mode
Grokzen commented 4 years ago

@ucasiggcas The error message is very descriptive enough to say what is happening. I would recommend you to read up on the basics of redis cluster before you continue to know all of these more basic questions. You can find the docs and tutorial here https://redis.io/topics/cluster-tutorial and https://redis.io/topics/cluster-spec

In short, the concept of databases and selecting different ones in a cluster mode do not exists any longer. The concept of segmenting the data into smaller logic databases is not possible in a clustered environment.

In general what you do is to build a good key space pattern and then data can live along side each other w/o problem in a single database.

ucasiggcas commented 4 years ago

thanks a lot