redis / redis-py

Redis Python client
MIT License
12.69k stars 2.53k forks source link

Commands fail with MOVED sometimes when using address_remap #3382

Open daveisfera opened 2 months ago

daveisfera commented 2 months ago

Version: What redis-py and what redis version is the issue happening on? 5.0.8 and Redis 7.0 (see here)

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure) Python 3.9.19 and Debian Bookworm

Description: Description of your issue, stack traces from errors and code that reproduces the issue Using address_remap allows connecting to the cluster, but about half the time, commands will fail with a MOVED error.

Here's the error output:

redis_client.hgetall("my_hash-1")
---------------------------------------------------------------------------
ResponseError                             Traceback (most recent call last)
Cell In[3], line 1
----> 1 redis_client.hgetall("my_hash-1")

File /usr/src/venv/lib/python3.9/site-packages/redis/commands/core.py:4966, in HashCommands.hgetall(self, name)
   4960 def hgetall(self, name: str) -> Union[Awaitable[dict], dict]:
   4961     """
   4962     Return a Python dict of the hash's name/value pairs
   4963 
   4964     For more information see https://redis.io/commands/hgetall
   4965     """
-> 4966     return self.execute_command("HGETALL", name)

File /usr/src/venv/lib/python3.9/site-packages/redis/cluster.py:1115, in RedisCluster.execute_command(self, *args, **kwargs)
   1112     continue
   1113 else:
   1114     # raise the exception
-> 1115     raise e

File /usr/src/venv/lib/python3.9/site-packages/redis/cluster.py:1101, in RedisCluster.execute_command(self, *args, **kwargs)
   1099         is_default_node = True
   1100 for node in target_nodes:
-> 1101     res[node.name] = self._execute_command(node, *args, **kwargs)
   1102 # Return the processed result
   1103 return self._process_result(args[0], res, **kwargs)

File /usr/src/venv/lib/python3.9/site-packages/redis/cluster.py:1151, in RedisCluster._execute_command(self, target_node, *args, **kwargs)
   1148     asking = False
   1150 connection.send_command(*args)
-> 1151 response = redis_node.parse_response(connection, command, **kwargs)
   1152 if command in self.cluster_response_callbacks:
   1153     response = self.cluster_response_callbacks[command](
   1154         response, **kwargs
   1155     )

File /usr/src/venv/lib/python3.9/site-packages/redis/client.py:565, in Redis.parse_response(self, connection, command_name, **options)
    563         options.pop(NEVER_DECODE)
    564     else:
--> 565         response = connection.read_response()
    566 except ResponseError:
    567     if EMPTY_RESPONSE in options:

File /usr/src/venv/lib/python3.9/site-packages/redis/connection.py:536, in AbstractConnection.read_response(self, disable_decoding, disconnect_on_error, push_request)
    534 if isinstance(response, ResponseError):
    535     try:
--> 536         raise response
    537     finally:
    538         del response  # avoid creating ref cycles

ResponseError: MOVED 14529 my-cluster-0001-001.my-cluster.5zcx5q.memorydb.us-east-1.amazonaws.com:6379