Пример #1
0
 def add(self, key, value, timeout=0):
     try:
         val = self._cache_master.getset(smart_str(key), pickle.dumps(value))
         self._cache_master.expire(smart_str(key), timeout or self.default_timeout)
         return val
     except redis.ConnectionError, e:
         logging.exception("ConnectionError %s" % e)
Пример #2
0
    def add(self, key, value, timeout=0):
        if isinstance(value, unicode):
            value = value.encode('utf-8')

        try:
            return self._cache.add(smart_str(key), value, timeout or self.default_timeout)
        except:
            logging.exception("memcache server desligado!")
Пример #3
0
 def get(self, key, default=None):
     try:
         val = self._cache_slave.get(smart_str(key))
         if val is None:
             return default
         else:
             return pickle.loads(val)
     except redis.ConnectionError, e:
         logging.exception("ConnectionError %s" % e)
Пример #4
0
 def get(self, key, default=None):
     try:
         val = self._cache.get(smart_str(key))
         if val is None:
             return default
         else:
             if isinstance(val, basestring):
                 return smart_unicode(val)
             else:
                 return val
     except:
         logging.exception("memcache server desligado!")
         return None
Пример #5
0
 def delete(self, key):
     self._cache.delete(smart_str(key))
Пример #6
0
 def set(self, key, value, timeout=0):
     if isinstance(value, unicode):
         value = value.encode('utf-8')
     self._cache.set(smart_str(key), value, timeout or self.default_timeout)
Пример #7
0
 def delete(self, key):
     try:
         self._cache_master.delete(smart_str(key))
     except redis.ConnectionError, e:
         logging.exception("ConnectionError %s" % e)
Пример #8
0
 def set(self, key, value, timeout=0):
     try:
         self._cache_master.set(smart_str(key), pickle.dumps(value))
         self._cache_master.expire(smart_str(key), timeout or self.default_timeout)
     except redis.ConnectionError as e:
         logging.exception("ConnectionError %s" % e)