Permalink
Browse files

Redis now has a lazy connection pool.

  • Loading branch information...
1 parent c0613fa commit 63dfdef25d66bf2baffe3c714bc4c8e2cb2e22bf @mmerickel mmerickel committed Mar 13, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 anykeystore/backends/redis.py
@@ -23,14 +23,17 @@ def __init__(self, db=0, host='localhost', port=6379,
self.port = int(port)
self.db = int(db)
self.key_prefix = key_prefix or ''
- self.pool = redis.ConnectionPool(host=host, port=port, db=db)
def _make_key(self, key):
return '%s%s' % (self.key_prefix, key)
+ _pool = None
def _get_conn(self):
"""The Redis connection, cached for this call"""
- return redis.Redis(connection_pool=self.pool)
+ if self._pool is None:
+ self._pool = redis.ConnectionPool(
+ host=self.host, port=self.port, db=self.db)
+ return redis.Redis(connection_pool=self._pool)
def retrieve(self, key):
data = self._get_conn().get(self._make_key(key))

0 comments on commit 63dfdef

Please sign in to comment.