python redis.exceptions.ConnectionError: Too many connections

created at 07-28-2021 views: 36

background

Use redis for a large number of channel subscriptions, and the operation prompts an error:

python redis.exceptions.ConnectionError: Too many connections

reason

The redis connection pool is too small

check the number of redis connection pools

redis-cli

127.0.0.1:6379> info clients

# View client status
connected_clients:3
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Check the number of connections
127.0.0.1:6379> CONFIG GET maxclients
1) "maxclients"
2) "10000"

# Set the maximum number of connections
127.0.0.1:6379> CONFIG set maxclients 10000
OK

Solution

Use redis connection pool and change the maximum number of connections to 2*31

import redis

redis_pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
conn = redis.Redis(connection_pool=redis_pool, max_connections=2 * 31)
created at:07-28-2021
edited at: 07-28-2021: