Commit 234c0a82 authored by Sean Bleier's avatar Sean Bleier

Created connection pool that lives across requests so that we can reuse…

Created connection pool that lives across requests so that we can reuse connections.  Removed close method, since we don't want to close connections at the end of a request.
parent c1168ac9
...@@ -14,6 +14,25 @@ except ImportError: ...@@ -14,6 +14,25 @@ except ImportError:
"Redis cache backend requires the 'redis-py' library") "Redis cache backend requires the 'redis-py' library")
class CacheConnectionPool(object):
_connection_pool = None
def get_connection_pool(self, host='127.0.0.1', port=6379, db=1, password=None,
socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict'):
if self._connection_pool is None:
kwargs = {
'db': db,
'password': password,
'socket_timeout': socket_timeout,
'encoding': charset,
'encoding_errors': errors,
'host': host,
'port': port
}
self._connection_pool = redis.ConnectionPool(**kwargs)
return self._connection_pool
pool = CacheConnectionPool()
class CacheKey(object): class CacheKey(object):
""" """
A stub string class that we can use to check if a key was created already. A stub string class that we can use to check if a key was created already.
...@@ -53,7 +72,8 @@ class CacheClass(BaseCache): ...@@ -53,7 +72,8 @@ class CacheClass(BaseCache):
else: else:
host = server or 'localhost' host = server or 'localhost'
port = 6379 port = 6379
self._cache = redis.Redis(host=host, port=port, db=db, password=password) self._cache = redis.Redis(host=host, port=port, db=db,
password=password, connection_pool=pool.get_connection_pool())
def make_key(self, key, version=None): def make_key(self, key, version=None):
""" """
...@@ -178,11 +198,6 @@ class CacheClass(BaseCache): ...@@ -178,11 +198,6 @@ class CacheClass(BaseCache):
for key, value in safe_data.iteritems())) for key, value in safe_data.iteritems()))
map(self.expire, safe_data, [timeout]*len(safe_data)) map(self.expire, safe_data, [timeout]*len(safe_data))
def close(self, **kwargs):
"""
Disconnect from the cache.
"""
self._cache.connection_pool.disconnect()
class RedisCache(CacheClass): class RedisCache(CacheClass):
""" """
......
File mode changed from 100644 to 100755
...@@ -30,7 +30,6 @@ class RedisCacheTests(unittest.TestCase): ...@@ -30,7 +30,6 @@ class RedisCacheTests(unittest.TestCase):
def tearDown(self): def tearDown(self):
self.cache.clear() self.cache.clear()
self.cache.close()
def get_cache(self, backend=None): def get_cache(self, backend=None):
if VERSION[0] == 1 and VERSION[1] < 3: if VERSION[0] == 1 and VERSION[1] < 3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment