Created
September 14, 2012 20:12
-
-
Save andymccurdy/3724431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from redis import ConnectionPool, Redis | |
class WaitingConnectionPool(ConnectionPool): | |
"Connection Pool that blocks if a connection is not available" | |
def make_connection(self): | |
while True: | |
if self._created_connections >= self.max_connections: | |
time.sleep(0.01) | |
self._created_connections += 1 | |
return self.connection_class(**self.connection_kwargs) | |
pool = WaitingConnectionPool('localhost', port=6379, max_connections=10) | |
redis = Redis(connection_pool=pool) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment