Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis is thread safe , so why use `BlockingConnectionPool` in redis-py

I use Django cache.I know Redis is thead-safe.

If BlockingConnectionPool is necessary, when I configure CACHE.

What does BlockingConnectionPool do?

When I need use BlockingConnectionPool?

like image 212
Ruoxuan.Wang Avatar asked Sep 06 '25 03:09

Ruoxuan.Wang


1 Answers

According to the official docs The "Blocking" in BlockingConnectionPool is not a reference to thread-safety, but rather to the fact that if there's no connection available this implementation will wait (block) for a specified number of seconds (timeout param) until one becomes available.

# Raises ConnectionError if connection is not available within before 10s timeout
pool = BlockingConnectionPool(timeout=10)

Specifying timeout=None will block indefinitely.

like image 84
Hans L Avatar answered Sep 09 '25 00:09

Hans L