From dd9d9e7591188ed130a4adc3d63eb1021456e41c Mon Sep 17 00:00:00 2001 From: GuoJing Date: Sat, 14 Mar 2015 01:48:36 +0800 Subject: [PATCH 1/2] rewrite format key --- beaker_extensions/redis_.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beaker_extensions/redis_.py b/beaker_extensions/redis_.py index b8bb458..b181485 100644 --- a/beaker_extensions/redis_.py +++ b/beaker_extensions/redis_.py @@ -25,6 +25,7 @@ def __init__(self, **params): self.db = params.pop('db', None) self.dbpass = params.pop('password', None) + self.format_key = params.pop('format_key', self._format_key) NoSqlManager.__init__(self, namespace, url=url, @@ -43,10 +44,10 @@ def open_connection(self, host, port, **params): **params) def __contains__(self, key): - return self.db_conn.exists(self._format_key(key)) + return self.db_conn.exists(self.format_key(key)) def set_value(self, key, value, expiretime=None): - key = self._format_key(key) + key = self.format_key(key) # # beaker.container.Value.set_value calls NamespaceManager.set_value @@ -69,7 +70,7 @@ def set_value(self, key, value, expiretime=None): self.db_conn.set(key, serialized_value) def __delitem__(self, key): - self.db_conn.delete(self._format_key(key)) + self.db_conn.delete(self.format_key(key)) def _format_key(self, key): return 'beaker:%s:%s' % (self.namespace, key.replace(' ', '\302\267')) From cfc3978f3aeeec70df20917d0f7accf68c77167c Mon Sep 17 00:00:00 2001 From: GuoJing Date: Sat, 14 Mar 2015 02:20:14 +0800 Subject: [PATCH 2/2] use _format_beaker_key --- beaker_extensions/redis_.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beaker_extensions/redis_.py b/beaker_extensions/redis_.py index b181485..f4598b4 100644 --- a/beaker_extensions/redis_.py +++ b/beaker_extensions/redis_.py @@ -25,7 +25,7 @@ def __init__(self, **params): self.db = params.pop('db', None) self.dbpass = params.pop('password', None) - self.format_key = params.pop('format_key', self._format_key) + self._format_key = params.pop('format_key', self._format_beaker_key) NoSqlManager.__init__(self, namespace, url=url, @@ -44,10 +44,10 @@ def open_connection(self, host, port, **params): **params) def __contains__(self, key): - return self.db_conn.exists(self.format_key(key)) + return self.db_conn.exists(self._format_key(key)) def set_value(self, key, value, expiretime=None): - key = self.format_key(key) + key = self._format_key(key) # # beaker.container.Value.set_value calls NamespaceManager.set_value @@ -70,9 +70,9 @@ def set_value(self, key, value, expiretime=None): self.db_conn.set(key, serialized_value) def __delitem__(self, key): - self.db_conn.delete(self.format_key(key)) + self.db_conn.delete(self._format_key(key)) - def _format_key(self, key): + def _format_beaker_key(self, key): return 'beaker:%s:%s' % (self.namespace, key.replace(' ', '\302\267')) def _format_pool_key(self, host, port, db):