Merge pull request #382 from apa-1/master
Added password option for redis_cache and redis_session
This commit is contained in:
@@ -24,7 +24,7 @@ def RedisCache(*args, **vars):
|
|||||||
Usage example: put in models
|
Usage example: put in models
|
||||||
|
|
||||||
from gluon.contrib.redis_cache import RedisCache
|
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 db: redis db to use (0..16)
|
||||||
:param debug: if True adds to stats() the total_hits and misses
|
:param debug: if True adds to stats() the total_hits and misses
|
||||||
@@ -77,8 +77,9 @@ class RedisClient(object):
|
|||||||
MAX_RETRIES = 5
|
MAX_RETRIES = 5
|
||||||
RETRIES = 0
|
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.server = server
|
||||||
|
self.password = password
|
||||||
self.db = db or 0
|
self.db = db or 0
|
||||||
host, port = (self.server.split(':') + ['6379'])[:2]
|
host, port = (self.server.split(':') + ['6379'])[:2]
|
||||||
port = int(port)
|
port = int(port)
|
||||||
@@ -102,7 +103,7 @@ class RedisClient(object):
|
|||||||
|
|
||||||
self.cache_set_key = 'w2p:%s:___cache_set' % (self.request.application)
|
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):
|
def __call__(self, key, f, time_expire=300, with_lock=None):
|
||||||
if with_lock is None:
|
if with_lock is None:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def RedisSession(*args, **vars):
|
|||||||
"""
|
"""
|
||||||
Usage example: put in models
|
Usage example: put in models
|
||||||
from gluon.contrib.redis_session import RedisSession
|
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)
|
session.connect(request, response, db = sessiondb)
|
||||||
|
|
||||||
Simple slip-in storage for session
|
Simple slip-in storage for session
|
||||||
@@ -45,12 +45,13 @@ class RedisClient(object):
|
|||||||
_release_script = None
|
_release_script = None
|
||||||
|
|
||||||
def __init__(self, server='localhost:6379', db=None, debug=False,
|
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
|
"""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,
|
of sessions. The corresponding record will be deleted from the redis instance,
|
||||||
and there's virtually no need to run sessions2trash.py
|
and there's virtually no need to run sessions2trash.py
|
||||||
"""
|
"""
|
||||||
self.server = server
|
self.server = server
|
||||||
|
self.password = password
|
||||||
self.db = db or 0
|
self.db = db or 0
|
||||||
host, port = (self.server.split(':') + ['6379'])[:2]
|
host, port = (self.server.split(':') + ['6379'])[:2]
|
||||||
port = int(port)
|
port = int(port)
|
||||||
@@ -59,7 +60,7 @@ class RedisClient(object):
|
|||||||
self.app = current.request.application
|
self.app = current.request.application
|
||||||
else:
|
else:
|
||||||
self.app = ''
|
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:
|
if with_lock:
|
||||||
RedisClient._release_script = \
|
RedisClient._release_script = \
|
||||||
self.r_server.register_script(_LUA_RELEASE_LOCK)
|
self.r_server.register_script(_LUA_RELEASE_LOCK)
|
||||||
|
|||||||
Reference in New Issue
Block a user