The basic command is skipped. Please refer to the command details redis.io Official website or redis Chinese official website
Redis profile:
Redis is an open source (BSD licensed) in memory data structure storage system, which can be used as database, cache and message middleware. It supports many types of data structures, such as strings, hashes, lists, sets, sorted sets and range queries, bitmaps, hyperloglogs and geospatial index radius queries. Redis has built-in replication, Lua scripting, LRU occurrence, transactions and different levels of disk persistence. It also provides high availability through redis sentinel and cluster.
Voting system – vote only
Objective: To study the clinical effect of the methodDesign a scoring system that decreases with time. At the same time, achieve the hottest / newest by group.
Score calculation method:Final score = the number of votes supported by the article × a constant + article publishing time (UNIX time)
Article storage mode:
The key is article:92617 , expressed as the article with ID 92617 in the article table (` hmset ')
realization:Two zsets: one key is the article ID, and the score is $\ underline {release time} $; (latest) the other key is the article ID, and the score is stored in $/ underline {score} $. (hottest)
Prevent users from voting multiple times:Save the voted user ID with a set.
Function realization
Voting:Add one to the value of votes in hashHINCRBY
; the score of the corresponding article in the Zset of the record score increasesZINCRBY
; the corresponding set table that records the voting personnel is added to the user. (follow a transaction)
release:Generate the article ID and store the article informationhmset
Generate vote set, score and time ordered set.
obtain: zrevrange
/zrange
Get the hottest / latest articles_ IDS collection, by traversing the IDhgetall
Get all attribute key value pairs of each article.
grouping:Create a new set named group to save all articles_ id。
To enable access to the hottest / latest articles by group. zinterstore
command(compare the consumption time, which can be set to 60s before expiration)
get_group_articles()
Of course, add group to the hash of article_ ID to limit the number of articles grouped. (you should also be right when voting here score:programming Add points)