Example #1
0
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))
Example #2
0
from gluon.contrib.appconfig import AppConfig
# -------------------------------------------------------------------------
# once in production, remove reload=True to gain full speed
# -------------------------------------------------------------------------
myconf = AppConfig()

### Caching ###

if myconf.get('cache.cache') == 'redis':
    from gluon.contrib.redis_utils import RConn
    from gluon.contrib.redis_cache import RedisCache

    redis_host = str(myconf.get('cache.redis_host'))
    redis_port = str(myconf.get('cache.redis_port'))
    rconn = RConn(redis_host, redis_port)
    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()
        value = value.replace(' ', '')
        value = value.upper()
Example #3
0
from gluon.contrib.appconfig import AppConfig
# -------------------------------------------------------------------------
# once in production, remove reload=True to gain full speed
# -------------------------------------------------------------------------
myconf = AppConfig()

### Caching ###

if myconf.get('cache.cache') == 'redis':
    from gluon.contrib.redis_utils import RConn
    from gluon.contrib.redis_cache import RedisCache

    redis_host = str(myconf.get('cache.redis_host'))
    redis_port = str(myconf.get('cache.redis_port'))
    rconn = RConn(redis_host, redis_port)
    cache.redis = RedisCache(redis_conn=rconn, debug=True, with_lock=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()
        value = value.replace(' ', '')
        value = value.upper()