Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Redis now has a lazy connection pool.

  • Loading branch information...
commit 63dfdef25d66bf2baffe3c714bc4c8e2cb2e22bf 1 parent c0613fa
@mmerickel mmerickel authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 anykeystore/backends/redis.py
View
7 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))
Please sign in to comment.
Something went wrong with that request. Please try again.