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

ClusterWithReadReplicasConnectionPool with read_from_replicas causes dump. #502

Closed prabhakarjuzgar closed 5 months ago

prabhakarjuzgar commented 1 year ago

We are using redis-cluster py and have set up connection pool with class ClusterWithReadReplicasConnectionPool. One of the arguments that is passed is read_from_replicas. An object gets created. But when a get is performed and the required node is not found in the pool, a make_connection is called. This internally calls SSLConnection class from redis/connection.py which does not recognise read_from_replicas.

"Traceback (most recent call last):\", "File \"/opt/directory/venv/lib/python3.6/site-packages/rediscluster/connection.py\", line 364, in get_connection_by_node\ connection = self._available_connections.get(node[\"name\"], []).pop()", "IndexError: pop from empty list", "During handling of the above exception, another exception occurred:", "Traceback (most recent call last):", " File \"/opt/directory/venv/lib/python3.6/site-packages/rediscluster/client.py\", line 615, in _execute_command\ connection = self.connection_pool.get_connection_by_node(node)", " File \"/opt/directory/venv/lib/python3.6/site-packages/rediscluster/connection.py\", line 366, in get_connection_by_node\ connection = self.make_connection(node)", " File \"/opt/directory/venv/lib/python3.6/site-packages/rediscluster/connection.py\", line 273, in make_connection\ connection = self.connection_class(host=node[\"host\"], port=node[\"port\"], self.connection_kwargs)", " File \"/opt/directory/venv/lib/python3.6/site-packages/rediscluster/connection.py\", line 89, in init\ super(SSLClusterConnection, self).init(kwargs)", " File \"/opt/directory/venv/lib/python3.6/site-packages/redis/connection.py\", line 828, in init\ super(SSLConnection, self).init( ** kwargs)", "TypeError: init() got an unexpected keyword argument 'read_from_replicas'

Is read_from_replicas a valid argument for ClusterWithReadReplicasConnectionPool?

Many thanks in advance.

Grokzen commented 5 months ago

@prabhakarjuzgar In the latest code at least, all i can see is that read_from_replicas keyword do not follow down into the connection class anywhere and i am assuming you are using older code that might been broken. The read_from_replicas feature is mostly used and supported in a ClusterPipeline object when i try to trace where the argument is used today.

In general i suggest you migrate over to redis-py where all future cluster code will be written. They have must better support for all of the features that you want/need