def get_article_type_key(index): article_h_key = carticle.index_to_article_key(index) r = get_redis() if r.exists(article_h_key): pass else: pass
def save(self): article_cleave_word_key = cleave_word.create_cleave_word_key( self.article_index) r = get_redis() article_leave_word_value = self.self.visitor_email + separator_flag + self.index + separator_flag + self.visitor_name + separator_flag + self.time + separator_flag + self.leave_word r.lpush(article_cleave_word_key, article_leave_word_value) r.save()
def get_blog_leave_words(index): blog_leave_word_key = cleave_word.create_cleave_word_key(index) r = get_redis() leave_words = [] leave_words_list = r.lrange(blog_leave_word_key, 0, r.llen(blog_leave_word_key) - 1) for leave_word in leave_words_list: leave_words.append( cleave_word.unserial_leave_word_from_str(leave_word)) return leave_words
def save(self): self.create_article_index() self.create_article_h_key() self.create_url() r = get_redis() r.hset(self.article_h_key, 'title', self.title) # r.hset(self.article_h_key, 'context', self.context) # r.hset(self.article_h_key, 'slug', self.slug) # r.hset(self.article_h_key, 'time', self.time) # r.hset(self.article_h_key, 'article_h_key', self.article_h_key) # r.hset(self.article_h_key, 'url', self.url) # r.hset(self.article_h_key, 'read_times', self.read_times) r.hset(self.article_h_key, 'type', self.type) r.save()
def get_article_type_detail(): r = get_redis() type_list = carticle.get_article_type_list() article_type_detail_list = [] for type in type_list: article_type_info = carticle_type_info() article_type_info.type_name = type article_type_list_key = carticle.create_type_list_key(type) type_info_list = r.lrange(article_type_list_key, 0, r.llen(article_type_list_key) - 1) for type_info in type_info_list: article_tag = ccarticle_tag() article_tag.title, article_tag.url = carticle.unserial_from_list( type_info) article_type_info.article_tag_list.append(article_tag) article_type_info.type_article_number = len( article_type_info.article_tag_list) article_type_detail_list.append(article_type_info) return article_type_detail_list
def get_article(index): article = carticle() article.index = index article.create_article_h_key() r = get_redis() if r.exists(article.article_h_key): r.hincrby(article.article_h_key, 'read_times') article.title = r.hget(article.article_h_key, 'title') article.context = r.hget(article.article_h_key, 'context') article.slug = article.slug = r.hget(article.article_h_key, 'slug') article.time = r.hget(article.article_h_key, 'time') article.article_h_key = r.hget(article.article_h_key, 'article_h_key') article.url = r.hget(article.article_h_key, 'url') article.read_times = r.hget(article.article_h_key, 'read_times') article.type = r.hget(article.article_h_key, 'type') r.save() return article else: return None
def save_article_to_type_detail(self): article_type_key = self.create_type_list_key(self.type) article_type_value = self.serial_to_list() r = get_redis() r.lpush(article_type_key, article_type_value) r.save()
def get_article_type_list(): r = get_redis() article_type_list = r.smembers('article_type_set') return article_type_list
def add_article_type(article_type): r = get_redis() r.sadd('article_type_set', article_type) r.save()
def create_article_index(self): r = get_redis() self.index = r.incr('__article_index__') r.save()