Open
Description
Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!
Version: 5.0.1
Platform: Python 3.10.12
Description:
We have a requirement of using address_remap
for addresses which are not accessible from out environment. However, ,this does not work. The function keeps getting called multiple times almost as in an endless loop, and the program eventually times out since the remapping seems to have not worked properly.
Code to reproduce(replace the IPs and mapping with appropriate values):
import asyncio
from redis.asyncio.cluster import RedisCluster, ClusterNode
# Define the address remap function with added print statements
def address_remap(address):
host, port = address
remap_dict = {
("10.10.28.60", 6379): ("redis-address-1", 6379),
("10.10.28.30", 6379): ("redis-address-1", 6380),
}
remapped_address = remap_dict.get((host, port), (host, port))
print(f"Remapping address {host}:{port} to {remapped_address[0]}:{remapped_address[1]}")
# return remapped_address
return remap_dict.get((host, str(port)), (host, port))
async def main():
# Initialize the RedisCluster client with address remapping
nodes = [{"host": "redis-address-1", "port": 6379}]
redis_cluster = await RedisCluster(
startup_nodes=[ClusterNode(**node) for node in nodes],
address_remap=address_remap,
decode_responses=True
)
# Print to indicate successful connection
print("Successfully connected to Redis Cluster.")
# Example set and get calls with print statements to demonstrate success
await redis_cluster.set("foo", "bar")
print("Successfully set 'foo' to 'bar'.")
value = await redis_cluster.get("foo")
print(f"Successfully retrieved 'foo' with value: {value}")
# Closing the connection
await redis_cluster.close()
print("Connection closed.")
# Running the main coroutine
if __name__ == "__main__":
asyncio.run(main())