Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding check for an existing redis-connection as we want to use the c…

…onnection pooling in redis-py which will be put out of play if we keep creating a new StrictRedis object on every request.
  • Loading branch information...
commit 367d22a240048bb4303cf66c07b7f72cfd3c5391 1 parent d0006ca
Svante Paldan authored
Showing with 20 additions and 3 deletions.
  1. +20 −3 beaker_extensions/redis_.py
View
23 beaker_extensions/redis_.py
@@ -13,12 +13,29 @@
log = logging.getLogger(__name__)
class RedisManager(NoSqlManager):
- def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ def __init__(self,
+ namespace,
+ url=None,
+ data_dir=None,
+ lock_dir=None,
+ **params):
self.db = params.pop('db', None)
- NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+ NoSqlManager.__init__(self,
+ namespace,
+ url=url,
+ data_dir=data_dir,
+ lock_dir=lock_dir,
+ **params)
def open_connection(self, host, port, **params):
- self.db_conn = StrictRedis(host=host, port=int(port), db=self.db, **params)
+ if (hasattr(self, 'db_conn') and
+ self.db_conn.host == host and
+ self.db_conn.port == port:
+ return
+ self.db_conn = StrictRedis(host=host,
+ port=int(port),
+ db=self.db,
+ **params)
def __contains__(self, key):
return self.db_conn.exists(self._format_key(key))
Please sign in to comment.
Something went wrong with that request. Please try again.