def set_redis_cache(): import pickle import redis import json try: r = redis.Redis(host='192.168.95.229', port=6379, db=0, password='******') testd = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} #user = {} #user['username'] = '******' #user['dept'] = "TVB" r.delete("test") r.hmset("test", testd) r.expire("test", 60) #p_mydict = pickle.dumps(testd) ##r.set('test', 'set from slave') #r.hmset ("test",p_mydict) rconn = RConn(host='192.168.95.229', port=6379, db=0, password='******') cache.redis = RedisCache(redis_conn=rconn, debug=True) #favorite_color = {"lion": "yellow", "kitty": "red"} cache.redis.delete("test") cache.redis.cache_it('test', testd, 180) #return cache.redis.stats() except Exception as ex: return dict(error=str(ex) + " on line " + str(sys.exc_traceback.tb_lineno))
def set_redis_session(): try: #from gluon.contrib.redis_utils import RConn rconn = RConn(host='192.168.95.229', port=6379, db=0, password='******') sessiondb = RedisSession(redis_conn=rconn, with_lock=True, session_expiry=False) session.connect(request, response, db=sessiondb) session.vuongtm = 'Chao em' except Exception as ex: return ex
def setUp(self): request = Request(env={}) request.application = 'a' request.controller = 'c' request.function = 'f' request.folder = 'applications/admin' response = Response() session = Session() session.connect(request, response) from gluon.globals import current current.request = request current.response = response current.session = session self.current = current rconn = RConn(host='localhost') self.db = RedisSession(redis_conn=rconn, session_expiry=False) self.tname = 'testtablename' return current
session.connect(request, response, db=db) # --------------------------------------------------------------------- # or store session in Memcache, Redis, etc. # from gluon.contrib.memdb import MEMDB # from google.appengine.api.memcache import Client # session.connect(request, response, db = MEMDB(Client())) # --------------------------------------------------------------------- if myconf.get('cache.cache') == 'redis': # If we have redis in the stack, let's use it for sessions from gluon.contrib.redis_utils import RConn from gluon.contrib.redis_session import RedisSession redis_host = str(myconf.get('cache.redis_host')) redis_port = str(myconf.get('cache.redis_port')) rconn = RConn(redis_host, redis_port) sessiondb = RedisSession(redis_conn=rconn, session_expiry=False) session.connect(request, response, db=sessiondb) # ------------------------------------------------------------------------- # by default give a view/generic.extension to all actions from localhost # none otherwise. a pattern can be 'controller/function.extension' # ------------------------------------------------------------------------- response.generic_patterns = ['*.json', '*.xml', '*.load', '*.html'] # ------------------------------------------------------------------------- # choose a style for forms # ------------------------------------------------------------------------- response.formstyle = myconf.get( 'forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other response.form_label_separator = myconf.get('forms.separator') or ''
# ------------------------------------------------------------------------- # once in production, comment out the following line # ------------------------------------------------------------------------- from gluon.custom_import import track_changes; track_changes(True) configuration = AppConfig(reload=True) ### Caching ### if configuration.get('cache.cache') == 'redis': from gluon.contrib.redis_utils import RConn from gluon.contrib.redis_cache import RedisCache rconn = RConn() cache.redis = RedisCache(redis_conn=rconn, debug=True) # use redis as cache cache.ram = cache.disk = cache.redis #### Custom validators begin ##### class IS_IBAN(object): def __init__(self, error_message=T('Invalid IBAN')): self.error_message = error_message def __call__(self, value): # remove whitespace, before, after and in string value = value.strip()