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 316 forks source link

use redis-py-cluster unable to connect to redis cluster in python 2.7 #518

Closed RuoCJ closed 8 months ago

RuoCJ commented 8 months ago

I follow the official documents: https://redis-py-cluster.readthedocs.io/en/master/ The example given is writing code to connect to my Redis cluster, but an error was reported: RedisCluster. exceptions. RedisClusterException: ERROR sending 'config get cluster require full coverage' command to Redis server: {'host ': u'196.2.xx. xx', 'server_ Type ':' slave ',' port ': 8xxxL,' name ':' 196.2.xxx. xx: 8xxx ', the strangest thing is that this IP address is not present in my code

# -*- coding: utf-8 -*-
from rediscluster import RedisCluster
startup_nodes = [
    {"host": "host1", "port": "port1"},
    {"host": "host2", "port": "port2"},
    ...
]
# 构建StrictRedisCluster对象
src = RedisCluster(startup_nodes=startup_nodes, decode_responses=True)
# 获取键为name
name = src.get('20231024')
src.close()
print(name)
Grokzen commented 8 months ago

@RuoCJ Interesting case. But in general, the code here do not do any magic or adding of hosts or ports by itself if you do not specify it. If you have a startup_node that can be reached by any name or ip, it will find the cluster and ask the cluster for the config, and as you mention in the error, it has found a host and port that the cluster is on and at some point, one of the nodes have answered back with the cluster configuration and that is where it has picked up the ip+port.

My wild guess tho is that you somehow in your configuration on your machine where you run this code, can do a DNS lookup to one of the host string names you have specified in the startup_nodes variable so if you would do ping host1 for instance, it would get an IP, and it would attempt to reach the cluster on that ip to find the cluster configuration from it.

If that is not the truth, then you have to dig deeper and really root out where this comes from.

Lastly, this repo is since a long time ago now part of redis-py. No fixes of patches will be added to this repo and you are encouraged to migrate over to redis-py moving forward for all your redis-cluster needs

RuoCJ commented 8 months ago

@RuoCJ Interesting case. But in general, the code here do not do any magic or adding of hosts or ports by itself if you do not specify it. If you have a startup_node that can be reached by any name or ip, it will find the cluster and ask the cluster for the config, and as you mention in the error, it has found a host and port that the cluster is on and at some point, one of the nodes have answered back with the cluster configuration and that is where it has picked up the ip+port.

My wild guess tho is that you somehow in your configuration on your machine where you run this code, can do a DNS lookup to one of the host string names you have specified in the startup_nodes variable so if you would do ping host1 for instance, it would get an IP, and it would attempt to reach the cluster on that ip to find the cluster configuration from it.

If that is not the truth, then you have to dig deeper and really root out where this comes from.

Lastly, this repo is since a long time ago now part of redis-py. No fixes of patches will be added to this repo and you are encouraged to migrate over to redis-py moving forward for all your redis-cluster needs

Due to the Python version, I am unable to use the higher version of redis-py, so I am unable to use redis-py to connect to the Redis cluster. The solution to this problem is to add parameters: skip_session_full_coverage_check=True