Description
Version: redis-py 4.5.5 and Redis 5.0.7-2ubuntu0.1
Platform: Python 3.10.11 on Ubuntu 20.04.6 LTS (Focal Fossa)
Description:
I am using the redis-py asyncio client in a service application. After several hours of running fine occasionally the error "Connection closed by server." is logged. This happens both for local Redis instances connected via TCP as well as for remote Redis instances connected via network TCP.
The settings for Redis are
timeout 0
tcp-keepalive 300
When I check the process with lsof
I can see the number of Redis connections slowly rise over time capping out at around 20 or so. The program should not need that many simultaneous connections so I would guess a lot of these connection are stale.
There seem to be several parameters in redis-py available to influence the connection handling and the most promising to me seem to be retry_on_timeout=True
, socket_keepalive=True
and health_check_interval=X
. However documentation for these parameters is very limited.
What would be the best practice to solve such an issue? I would like to avoid unneeded overhead.