Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created September 14, 2012 20:12
Show Gist options
  • Save andymccurdy/3724431 to your computer and use it in GitHub Desktop.
Save andymccurdy/3724431 to your computer and use it in GitHub Desktop.
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