def set_redis_key(key,value,lifecycle): if lifecycle > MAX_CACHE_LIFE or lifecycle == 0: lifecycle = MAX_CACHE_LIFE try: cache_client = get_cache_client() cache_client.setex(key,value,cPickle.dump(value)) except Exception,ex: print "set_redis_key is error:",ex
def delete_redis_key( key ): try: cache_client = get_cache_client() cache_client.delete( key ) except Exception ,e : print 'delete_redis_key is error', Exception, e
#-*-coding=utf-8-*- from wm_geek.config.const_value import MAX_CACHE_LIFE from wm_geek.cache import get_cache_client import functools import cPickle cache_client = get_cache_client() FAKE_VALUE = "###FAKE_VALUE###" def deco_cache(prefix,recycle=60): def fun_picker(func): @functools.wraps(func) def checker(*args,**kw): key = '{0}_{1}'.format(prefix,"_".join([str(i).replace(" ","_") for i in args])) value = None if kw.get("use_cache",True): try: value = cache_client.get(key) except: value = None if value: value = cPickle.load(value) if value == FAKE_VALUE: return None else: value = func(*args,**kw) try: if value != None: if recycle == 0: