예제 #1
0
 def save(self, storage=None):
     " Save object to redis storage"
     if self.embedded:
         logging.warning('You should save embedded objects with high level object')
         return
     if not self.id:
         new_id = RedisConn.incr(mkey(REDIS_NAMESPACE,
                                      self.__class__.__name__.lower() + '_key'))
         if self.__salt__:
             self.id = hashlib.md5(str(new_id) + self.__salt__).hexdigest()
         else:
             self.id = new_id
     RedisConn.set(mkey(REDIS_NAMESPACE, self.collection_name, self.id),
                   json.dumps(self.__instdict__))
     if self.expire != None:
         RedisConn.expire(mkey(REDIS_NAMESPACE, self.collection_name,
                               self.id), self.expire)
예제 #2
0
    def update(self, storage=None, **kwargs):
        '''update time expire'''
        print 'updating::'
        id = mkey(REDIS_NAMESPACE, self.collection_name, self.id)

        if 'expire' in kwargs:
            print TIME_TO_OVERWRITE_CLIENT_COOKIE, RedisConn.ttl(id)
            if  TIME_TO_OVERWRITE_CLIENT_COOKIE > RedisConn.ttl(id):
                result = RedisConn.expire(id, kwargs['expire'])
                logging.info('UPDATE LIFETIME TO: %s SECONDS'
                             % kwargs['expire'])
                return result
            else:
                logging.debug('non_update_SESSION')

        else:
            raise Exception('unknown action!!!')