Beispiel #1
0
 def set(cls, key, val, time_out=0):
     ret = True
     try:
         cls._db.set(key, val)  # TODO time_out
     except Exception, e:
         Log.warning('Redis set %s failed(%s)', key, str(e))
         return False
Beispiel #2
0
 def get(cls, key):
     val = None
     try:
         val = cls._db.get(key)
     except Exception, e:
         Log.warning('Redis get %s failed(%s)', key, str(e))
         return False
Beispiel #3
0
 def __reconnect(cls):
     if cls.__mc_conn is not None:
         try:
             cls.__mc_conn.disconnect_all()
         except Exception, e:
             Log.warning('memcache disconnect(%s)', str(e))
         cls.__mc_conn = None
Beispiel #4
0
 def push(cls, key, value):
     ret = False
     try: 
         ret = cls._db.rpush(key, value)
     except Exception, e:
         Log.warning('Redis push key %s failed(%s)',key, str(e))
         return False
Beispiel #5
0
 def push(cls, key, value):
     ret = False
     try:
         ret = cls._db.rpush(key, value)
     except Exception, e:
         Log.warning('Redis push key %s failed(%s)', key, str(e))
         return False
Beispiel #6
0
 def get_all_keys(cls):
     ret = []
     try:
         ret = cls._db.keys()
     except Exception, e:
         Log.warning('Redis get all keys failed(%s)', str(e))
         return False
Beispiel #7
0
 def __reconnect(cls):
     if cls.__mc_conn is not None:
         try:
             cls.__mc_conn.disconnect_all()
         except Exception, e:
             Log.warning('memcache disconnect(%s)', str(e))
         cls.__mc_conn = None
Beispiel #8
0
 def is_key_exist(cls, key):
     ret = False
     try:
         ret = cls._db.exists(key)
     except Exception, e:
         Log.warning('Redis is key exist %s failed(%s)', key, str(e))
         return False
Beispiel #9
0
 def get_list_top(cls, key, size=1):
     ret = False
     try:
         ret = cls._db.lrange(key, 0, size - 1)
     except Exception, e:
         Log.warning('Redis pop key %s failed(%s)', key, str(e))
         return False
Beispiel #10
0
 def get_size(cls):
     ret = 0
     try: 
         ret = cls._db.dbsize()
     except Exception, e:
         Log.warning('Redis get size failed(%s)',str(e))
         return False
Beispiel #11
0
 def get_all_keys(cls):
     ret = []
     try: 
         ret = cls._db.keys()
     except Exception, e:
         Log.warning('Redis get all keys failed(%s)',str(e))
         return False
Beispiel #12
0
 def pop(cls, key):
     ret = False
     try:
         ret = cls._db.lpop(key)
     except Exception, e:
         Log.warning('Redis pop key %s failed(%s)', key, str(e))
         return False
Beispiel #13
0
 def get(cls, key):
     val = None
     try:
         val = cls._db.get(key)
     except Exception, e:
         Log.warning('Redis get %s failed(%s)', key, str(e))
         return False
Beispiel #14
0
 def set(cls, key, val, time_out = 0):
     ret = True
     try: 
         cls._db.set(key, val) # TODO time_out
     except Exception, e:
         Log.warning('Redis set %s failed(%s)', key, str(e))
         return False
Beispiel #15
0
 def pop(cls, key):
     ret = False
     try: 
         ret = cls._db.lpop(key)
     except Exception, e:
         Log.warning('Redis pop key %s failed(%s)',key, str(e))
         return False
Beispiel #16
0
 def get_list_top(cls, key, size=1):
     ret = False
     try: 
         ret = cls._db.lrange(key, 0, size-1)
     except Exception, e:
         Log.warning('Redis pop key %s failed(%s)',key, str(e))
         return False
Beispiel #17
0
 def get_size(cls):
     ret = 0
     try:
         ret = cls._db.dbsize()
     except Exception, e:
         Log.warning('Redis get size failed(%s)', str(e))
         return False
Beispiel #18
0
 def is_key_exist(cls, key):
     ret = False
     try: 
         ret = cls._db.exists(key)
     except Exception, e:
         Log.warning('Redis is key exist %s failed(%s)',key, str(e))
         return False
Beispiel #19
0
 def delete(cls, key):
     try:
         cls.__mc_conn.delete(key)
     except Exception, e:
         Log.warning('memcache delete %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             cls.__mc_conn.delete(key)
         except Exception, e1:
             Log.warning('memcache re-delete %s failed(%s)', key, str(e1))
Beispiel #20
0
 def delete(cls, key):
     try:
         cls.__mc_conn.delete(key)
     except Exception, e:
         Log.warning('memcache delete %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             cls.__mc_conn.delete(key)
         except Exception, e1:
             Log.warning('memcache re-delete %s failed(%s)', key, str(e1))
Beispiel #21
0
 def get(cls, key):
     val = None
     try:
         val = cls.__mc_conn.get(key)
     except Exception, e:
         Log.warning('memcache get %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             val = cls.__mc_conn.get(key)
         except Exception, e1:
             val = None
             Log.warning('memcache re-get %s failed(%s)', key, str(e1))
Beispiel #22
0
 def set(cls, key, val, time_out = 0):
     ret = True
     try: 
         cls.__mc_conn.set(key, val, time_out)
     except Exception, e:
         Log.warning('memcache set %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             cls.__mc_conn.set(key, val, time_out)
         except Exception, e1:
             ret = False
             Log.warning('memcache re-set %s failed(%s)', key, str(e1))
Beispiel #23
0
 def get(cls, key):
     val = None
     try:
         val = cls.__mc_conn.get(key)
     except Exception, e:
         Log.warning('memcache get %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             val = cls.__mc_conn.get(key)
         except Exception, e1: 
             val = None
             Log.warning('memcache re-get %s failed(%s)', key, str(e1))
Beispiel #24
0
 def set(cls, key, val, time_out=0):
     ret = True
     try:
         cls.__mc_conn.set(key, val, time_out)
     except Exception, e:
         Log.warning('memcache set %s failed(%s)', key, str(e))
         cls.__reconnect()
         try:
             cls.__mc_conn.set(key, val, time_out)
         except Exception, e1:
             ret = False
             Log.warning('memcache re-set %s failed(%s)', key, str(e1))
Beispiel #25
0
 def delete(cls, key):
     try:
         cls._db.delete(key)
     except Exception, e:
         Log.warning('Redis delete %s failed(%s)', key, str(e))
         return False
Beispiel #26
0
 def delete(cls, key):
     try:
         cls._db.delete(key)
     except Exception, e:
         Log.warning('Redis delete %s failed(%s)', key, str(e))
         return False