backward compatible syntax for redis
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
## trunk
|
## 2.14.1
|
||||||
|
|
||||||
- new JWT implementation (experimental)
|
- new JWT implementation (experimental)
|
||||||
- new gluon.contrib.redis_scheduler
|
- new gluon.contrib.redis_scheduler
|
||||||
- BREAKING: changes to gluon.contrib.redis_cache
|
- BREAKING: changes to gluon.contrib.redis_cache
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
session.connect(request, response, db = sessiondb)
|
session.connect(request, response, db = sessiondb)
|
||||||
|
|
||||||
|
|
||||||
## 2.13.1-2
|
## 2.13.*
|
||||||
|
|
||||||
- fixed a security issue in request_reset_password
|
- fixed a security issue in request_reset_password
|
||||||
- added fabfile.py
|
- added fabfile.py
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ import random
|
|||||||
from gluon import current
|
from gluon import current
|
||||||
from gluon.cache import CacheAbstract
|
from gluon.cache import CacheAbstract
|
||||||
from gluon.contrib.redis_utils import acquire_lock, release_lock
|
from gluon.contrib.redis_utils import acquire_lock, release_lock
|
||||||
from gluon.contrib.redis_utils import register_release_lock, RConnectionError
|
from gluon.contrib.redis_utils import register_release_lock, RConnectionError, RConn
|
||||||
|
|
||||||
logger = logging.getLogger("web2py.cache.redis")
|
logger = logging.getLogger("web2py.cache.redis")
|
||||||
|
|
||||||
locker = thread.allocate_lock()
|
locker = thread.allocate_lock()
|
||||||
|
|
||||||
|
|
||||||
def RedisCache(*args, **vars):
|
def RedisCache(redis_conn=None, debug=False, with_lock=False, fail_gracefully=False, db=None):
|
||||||
"""
|
"""
|
||||||
Usage example: put in models::
|
Usage example: put in models::
|
||||||
|
|
||||||
@@ -81,11 +81,18 @@ def RedisCache(*args, **vars):
|
|||||||
- we scan the keys and then delete them
|
- we scan the keys and then delete them
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# for backward compatibility
|
||||||
|
if isinstance(redis_conn, str):
|
||||||
|
host, port = redis_conn.split(':')
|
||||||
|
redis_conn = RConn(host=host, port=int(port), db=db)
|
||||||
|
|
||||||
locker.acquire()
|
locker.acquire()
|
||||||
try:
|
try:
|
||||||
instance_name = 'redis_instance_' + current.request.application
|
instance_name = 'redis_instance_' + current.request.application
|
||||||
if not hasattr(RedisCache, instance_name):
|
if not hasattr(RedisCache, instance_name):
|
||||||
setattr(RedisCache, instance_name, RedisClient(*args, **vars))
|
setattr(RedisCache, instance_name,
|
||||||
|
RedisClient(redis_conn=redis_conn, debug=debug,
|
||||||
|
with_lock=with_lock, fail_gracefully=fail_gracefully))
|
||||||
return getattr(RedisCache, instance_name)
|
return getattr(RedisCache, instance_name)
|
||||||
finally:
|
finally:
|
||||||
locker.release()
|
locker.release()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import logging
|
|||||||
import thread
|
import thread
|
||||||
from gluon import current
|
from gluon import current
|
||||||
from gluon.storage import Storage
|
from gluon.storage import Storage
|
||||||
from gluon.contrib.redis_utils import acquire_lock, release_lock
|
from gluon.contrib.redis_utils import acquire_lock, release_lock, RConn
|
||||||
from gluon.contrib.redis_utils import register_release_lock
|
from gluon.contrib.redis_utils import register_release_lock
|
||||||
|
|
||||||
logger = logging.getLogger("web2py.session.redis")
|
logger = logging.getLogger("web2py.session.redis")
|
||||||
@@ -19,7 +19,7 @@ logger = logging.getLogger("web2py.session.redis")
|
|||||||
locker = thread.allocate_lock()
|
locker = thread.allocate_lock()
|
||||||
|
|
||||||
|
|
||||||
def RedisSession(*args, **vars):
|
def RedisSession(redis_conn, session_expiry=False, with_lock=False, db=None):
|
||||||
"""
|
"""
|
||||||
Usage example: put in models::
|
Usage example: put in models::
|
||||||
|
|
||||||
@@ -39,11 +39,17 @@ def RedisSession(*args, **vars):
|
|||||||
Simple slip-in storage for session
|
Simple slip-in storage for session
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# for backward compatibility
|
||||||
|
if isinstance(redis_conn, str):
|
||||||
|
host, port = redis_conn.split(':')
|
||||||
|
redis_conn = RConn(host=host, port=int(port), db=db)
|
||||||
|
|
||||||
locker.acquire()
|
locker.acquire()
|
||||||
try:
|
try:
|
||||||
instance_name = 'redis_instance_' + current.request.application
|
instance_name = 'redis_instance_' + current.request.application
|
||||||
if not hasattr(RedisSession, instance_name):
|
if not hasattr(RedisSession, instance_name):
|
||||||
setattr(RedisSession, instance_name, RedisClient(*args, **vars))
|
setattr(RedisSession, instance_name,
|
||||||
|
RedisClient(redis_conn, session_expiry=session_expiry, with_lock=with_lock))
|
||||||
return getattr(RedisSession, instance_name)
|
return getattr(RedisSession, instance_name)
|
||||||
finally:
|
finally:
|
||||||
locker.release()
|
locker.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user