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

The first node of cluster can not connect #507

Closed Vector-Cross closed 1 year ago

Vector-Cross commented 1 year ago

Problem

As long as the key is in the first node, my program will report an error. For example, three keys (test113, test114, test115) in (192.168.0.113:6379, 192.168.0.114:6379, 192.168.0.115:6379) correspondingly. And startup_nodes[0]'s host == "192.168.0.113" Then I cannot connect "192.168.0.113", redis_store.get('test113') will report an error. But the other two is ok. If I change the order, startup_nodes[0]'s host == "192.168.0.114", redis_store.get('test114') will report an error. the other two is ok. redis_store.get('test113') will be ok now.

from rediscluster import RedisCluster
startup_nodes = [
    {"host": "192.168.0.113", "port": 6379},
    {"host": "192.168.0.113", "port": 6380},
    {"host": "192.168.0.114", "port": 6379},
    {"host": "192.168.0.114", "port": 6380},
    {"host": "192.168.0.115", "port": 6379},
    {"host": "192.168.0.115", "port": 6380}
]
redis_store = RedisCluster(
    startup_nodes=startup_nodes,
    skip_full_coverage_check=True,
    password=REDIS_PASSWORD)
redis_store.get('test113')

Error info

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 1606, in get
    return self.execute_command('GET', name)
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 555, in execute_command
    return self._execute_command(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 714, in _execute_command
    raise e
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 630, in _execute_command
    connection.send_command(*args)
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 726, in send_command
    check_health=kwargs.get('check_health', True))
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 698, in send_packed_command
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 567, in connect
    self.on_connect()
  File "/usr/local/lib/python3.7/site-packages/rediscluster/connection.py", line 60, in on_connect
    super(ClusterConnection, self).on_connect()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 643, in on_connect
    auth_response = self.read_response()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 756, in read_response
    raise response
redis.exceptions.ResponseError: WRONGPASS invalid username-password pair or user is disabled.

Environment

OS Environment:armbian 5.77 Debian GNU/Linux 9 (stretch) Python Environment:docker python:3.7-alpine redis-py-cluster Version: 2.1.3 (redis 3.5.3)

Networks

redis cluster: {"host": "192.168.0.113", "port": 6379}, {"host": "192.168.0.113", "port": 6380}, {"host": "192.168.0.114", "port": 6379}, {"host": "192.168.0.114", "port": 6380}, {"host": "192.168.0.115", "port": 6379}, {"host": "192.168.0.115", "port": 6380} redis-client: 192.168.0.105 vilidation-client: 192.168.0.106

Redis Cluster Config

This should not be a problem with the redis configuration file. My vilidation-client with Windows System didn't encounter this problem.

Grokzen commented 1 year ago

@Vector-Cross Your error is clear as day what the problem is redis.exceptions.ResponseError: WRONGPASS invalid username-password pair or user is disabled. it is not a problem of reaching your nodes in any way. You get there and commands is sent there. The problem is that either your password you provided in your python code is wrong, or you have not deployed the correct password to all nodes in your cluster.

The only case you have here tho is that if you can show you configured the password correct and that you can prove that when sending the authentication command, the password is not the same as your variable REDIS_PASSWORD

Vector-Cross commented 1 year ago

I'm pretty sure the REDIS_PASSWORD is correct. My problem is I cann't connect the first node. How to explain the following cases. First, check password. code passed.

>>> from rediscluster import RedisCluster
>>> startup_nodes = [
...     {"host": "192.168.0.113", "port": 6379},
...     {"host": "192.168.0.113", "port": 6380},
...     {"host": "192.168.0.114", "port": 6379},   【# key "test" in this Node, can connect when not the first config】
...     {"host": "192.168.0.114", "port": 6380},
...     {"host": "192.168.0.115", "port": 6379},
...     {"host": "192.168.0.115", "port": 6380}
... ]
>>> redis_store = RedisCluster(
...     startup_nodes=startup_nodes,
...     skip_full_coverage_check=True,
...     password='Lj12369874.')
>>> redis_store.get("test")    【# Now can connect, means PASSWORD is correct】
【b'OK'】

Code not pass when Switch the squence of Startup_nodes

>>> from rediscluster import RedisCluster
>>> startup_nodes = [
...     {"host": "192.168.0.114", "port": 6379},   【# key "test" in this Node, switch to top cann't connect】
...     {"host": "192.168.0.113", "port": 6379},
...     {"host": "192.168.0.113", "port": 6380},
...     {"host": "192.168.0.114", "port": 6380},
...     {"host": "192.168.0.115", "port": 6379},
...     {"host": "192.168.0.115", "port": 6380}
... ]
>>> redis_store = RedisCluster(
...     startup_nodes=startup_nodes,
...     skip_full_coverage_check=True,
...     password='Lj12369874.')
>>> redis_store.get("test")    【# Now can not connect, just switch the squence of Startup_nodes】
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 1606, in get
    return self.execute_command('GET', name)
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 555, in execute_command
    return self._execute_command(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 714, in _execute_command
    raise e
  File "/usr/local/lib/python3.7/site-packages/rediscluster/client.py", line 630, in _execute_command
    connection.send_command(*args)
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 726, in send_command
    check_health=kwargs.get('check_health', True))
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 698, in send_packed_command
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 567, in connect
    self.on_connect()
  File "/usr/local/lib/python3.7/site-packages/rediscluster/connection.py", line 60, in on_connect
    super(ClusterConnection, self).on_connect()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 643, in on_connect
    auth_response = self.read_response()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 756, in read_response
    raise response
redis.exceptions.ResponseError: WRONGPASS invalid username-password pair or user is disabled.

@Grokzen