Directly on the code:
#Python3#-*-coding:utf-8-*-ImportRedisImportTimeone_week_in_seconds= 7 * 86400#If an article gets 200 likes, then this article is interestingVote_score = 86400/200defRedis_init (Redis):#article_time Record article release timeRedis.zadd ('Article_time', article_100408=1496662197, article_100635=1496669721, article_100716=1496660089) #Article_score Record article scoreRedis.zadd ('Article_score', article_100408=1496666517, article_100635=1496670153, article_100716=1496665705) #voted_article_id A user collection for an article with a record number of article_idRedis.sadd ('voted_100408','user_234487','user_253378','user_364680', 'user_132097','user_350917') #describe each article with a hashArticle_desc = {'title':'Kunlun','Link':'www.kunlun.com','Poster':'Fengge',' Time': 1441728000,'votes': 523} redis.hmset ('article_100408', Article_desc) Article_desc= {'title':'Zhuxian','Link':'www.zhuxian.com','Poster':'xiaoding',' Time': 1081440000,'votes': 677} redis.hmset ('article_100635', Article_desc) Article_desc= {'title':'Soushenji','Link':'www.soushenji.com','Poster':'Shuxiayehu', ' Time': 1187280000,'votes': 421} redis.hmset ('article_100635', Article_desc)defarticle_note (conn, user, article): Cutoff= Time.time ()-One_week_in_secondsifConn.zscore ('Article_time', article) <Cutoff:returnarticle_id= Article.partition ('_') [-1] ifConn.sadd ('Voted_'+article_id, user): Conn.zincrby ('Article_score', article, Vote_score) Conn.hincrby (article,'votes', 1) R= Redis. Strictredis (host='redis_server_ip', port=6379, password='redis_passwd', db=0) Redis_init (r) article_note (R),'use_115423','article_100408')
Resources:
"Redis Combat"
Redis Website Article poll