def add(cls, user_id, origin_id, create_time, site, category, title, text=None, raw=None): status = None cursor = None try: cursor = db_conn.execute("""insert into status (user_id, origin_id, create_time, site, category, title) values (%s,%s,%s,%s,%s,%s)""", (user_id, origin_id, create_time, site, category, title)) db_conn.commit() status_id = cursor.lastrowid if text is not None: redis_conn.set(cls.STATUS_REDIS_KEY %status_id, json_encode(text)) if raw is not None: redis_conn.set(cls.RAW_STATUS_REDIS_KEY %status_id, raw) cls._clear_cache(user_id, None, cate=category) status = cls.get(status_id) except IntegrityError: #log.warning("add status duplicated, ignore...") db_conn.rollback() finally: cursor and cursor.close() return status
def update_detail(self, detail): k = self.__class__.kv_db_key_task % self.id redis_conn.set(k, json_encode(detail)) return self.get_detail()
def set_profile(self, profile): redis_conn.set('/profile/%s' %self.id, json_encode(profile)) return self.get_profile()