From 31fcf515062e701e01d181662450370f209685a7 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 24 Feb 2014 19:01:27 -0500 Subject: [PATCH] Added password option for redis_cache and redis_session --- gluon/contrib/redis_cache.py | 7 ++++--- gluon/contrib/redis_session.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gluon/contrib/redis_cache.py b/gluon/contrib/redis_cache.py index 634b91f3..01b98d19 100644 --- a/gluon/contrib/redis_cache.py +++ b/gluon/contrib/redis_cache.py @@ -24,7 +24,7 @@ def RedisCache(*args, **vars): Usage example: put in models from gluon.contrib.redis_cache import RedisCache - cache.redis = RedisCache('localhost:6379',db=None, debug=True, with_lock=True) + cache.redis = RedisCache('localhost:6379',db=None, debug=True, with_lock=True, password=None) :param db: redis db to use (0..16) :param debug: if True adds to stats() the total_hits and misses @@ -77,8 +77,9 @@ class RedisClient(object): MAX_RETRIES = 5 RETRIES = 0 - def __init__(self, server='localhost:6379', db=None, debug=False, with_lock=False): + def __init__(self, server='localhost:6379', db=None, debug=False, with_lock=False, password=None): self.server = server + self.password = password self.db = db or 0 host, port = (self.server.split(':') + ['6379'])[:2] port = int(port) @@ -102,7 +103,7 @@ class RedisClient(object): self.cache_set_key = 'w2p:%s:___cache_set' % (self.request.application) - self.r_server = redis.Redis(host=host, port=port, db=self.db) + self.r_server = redis.Redis(host=host, port=port, db=self.db, password=self.password) def __call__(self, key, f, time_expire=300, with_lock=None): if with_lock is None: diff --git a/gluon/contrib/redis_session.py b/gluon/contrib/redis_session.py index 2daa8184..1e88f86c 100644 --- a/gluon/contrib/redis_session.py +++ b/gluon/contrib/redis_session.py @@ -21,7 +21,7 @@ def RedisSession(*args, **vars): """ Usage example: put in models from gluon.contrib.redis_session import RedisSession - sessiondb = RedisSession('localhost:6379',db=0, session_expiry=False) + sessiondb = RedisSession('localhost:6379',db=0, session_expiry=False, password=None) session.connect(request, response, db = sessiondb) Simple slip-in storage for session @@ -45,12 +45,13 @@ class RedisClient(object): _release_script = None def __init__(self, server='localhost:6379', db=None, debug=False, - session_expiry=False, with_lock=False): + session_expiry=False, with_lock=False, password=None): """session_expiry can be an integer, in seconds, to set the default expiration of sessions. The corresponding record will be deleted from the redis instance, and there's virtually no need to run sessions2trash.py """ self.server = server + self.password = password self.db = db or 0 host, port = (self.server.split(':') + ['6379'])[:2] port = int(port) @@ -59,7 +60,7 @@ class RedisClient(object): self.app = current.request.application else: self.app = '' - self.r_server = redis.Redis(host=host, port=port, db=self.db) + self.r_server = redis.Redis(host=host, port=port, db=self.db, password=self.password) if with_lock: RedisClient._release_script = \ self.r_server.register_script(_LUA_RELEASE_LOCK)