I have a Redis Cluster with 9 instances—3 masters and 6 slaves. I want to connect pyredis to this cluster and execute simple commands like get
and set
. Without informing pyredis of any of the slave nodes, this works fine. For example:
cc = ClusterClient(seeds=[("master1_ip",6379), ("master2_ip",6379), ("master3_ip",6379)], slave_ok=False)
cc.set("key", "value")
correctly sets "key" to "value" on the appropriate master instance. Furthermore, even if I list all the instances, as long as slave_ok
is still False
, get
and set
seem to behave correctly. For example:
cc = ClusterClient(seeds=[("master1_ip",6379), ("master2_ip",6379), ("master3_ip",6379), ("slave1_ip",6380), ("slave2_ip",6380), ("slave3_ip",6380), ("slave4_ip",6381), ("slave5_ip",6381), ("slave6_ip",6381)], slave_ok=False)
cc.get("key")
will similarly correctly get the value at "key". However, as soon as I toggle slave_ok
to True
in either of the above examples (with or without listing the slave instances in seeds
—I'm also not sure which form is correct), I get the following error:
pyredis.exceptions.PyRedisError: Slot moved to often or wrong shard_key, giving up,
and the get
or set
request is never processed by the cluster. It seems, at least, that requests are hitting the cluster, because preceding the above PyRedisError
, I see errors of the form pyredis.exceptions.ReplyError: MOVED (hashslot) (ip):(port)
—this seems like a response from the cluster telling pyredis that it should redirect a request from one instance/shard to another.
I'm curious as to the cause of this error. And furthermore, what does the slave_ok
option actually do/change? I thought that enabling it might allow me to do something like direct set
s to masters and get
s to slaves, but I can't find any description other than "Set to True if this Client should use slave nodes" in the documentation.
Thank you.