Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis py: when to use connection pool?

Tags:

python

redis

pool = redis.ConnectionPool(host='10.0.0.1', port=6379, db=0)
r = redis.Redis(connection_pool=pool)

vs.

r = redis.Redis(host='10.0.0.1', port=6379, db=0)

Those two works fine.

Whats the idea behind using connection pool? When would you use it?

like image 826
ealeon Avatar asked Feb 10 '16 13:02

ealeon


People also ask

Do you need connection pooling for Redis?

If we create a separate Redis connection for a thread it will be overhead for the Redis server. We need to have a pool of connections in multi-threaded environments to address these challenges. This allows us to talk to Redis from multiple threads while still getting the benefits of reused connections.

What is Redis connection pool?

Redis-py provides a connection pool for you from which you can retrieve a connection. Connection pools create a set of connections which you can use as needed (and when done - the connection is returned to the connection pool for further reuse).

What is Jedis connection pool?

Use JedisPool This allows you to talk to redis from multiple threads while still getting the benefits of reused connections. The JedisPool object is thread-safe and can be used from multiple threads at the same time. This pool should be configured once and reused.

How many connections Redis can handle?

Individual ElastiCache for Redis nodes support up to 65,000 concurrent client connections.


1 Answers

From the redis-py docs:

Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool instance to the connection_pool argument of the Redis class. You may choose to do this in order to implement client side sharding or have finer grain control of how connections are managed.

So, normally this is not something you need to handle yourself, and if you do, then you know!

like image 56
Linus Thiel Avatar answered Sep 20 '22 05:09

Linus Thiel