Read some articles, about the use of Redis, I think it is very good. Redis must be far more than just a cache to use. Redis is more like a well-implemented data structure server that provides services through the TCP stack protocol. Detailed descriptions are described below.
Http://database.51cto.com/art/201107/276333.htm
(In fact, the translation and supplement of http://highscalability.com/blog/2011/7/6/11-common-web-use-cases-solved-in-redis.html)
Show the latest list of items
The following statement is often used to show the latest items, and with more data, the query will undoubtedly become slower.
SELECT * from foo WHERE ... ORDER by Time DESC LIMIT
In a web app, queries such as "list up-to-date replies" are common.
Because the project was created in this order, it had to be sorted in order to output it.
< span class= "keyword" >
We assume that each comment in the database has a unique incrementing ID field. - each time a new comment is published, we add its ID to a redis list: Lpush latest.comments <ID>- We crop the list to a specified length, so redis just needs to save the latest 5,000 comments: LTRIM latest.comments 0 5000 FUNCTION get_latest_comments (start,num_items): id_list = Redis.lrange ( " latest.comments ", Start,start+num_items-1 ) IF id_list.length < num_items id_list = sql_db ( Span style= "COLOR: #800000" > " select ... ORDER by Time LIMIT ... " ;) End RETURN Id_list End
The SQL database (or other type of database on the hard disk) is only triggered when the user needs to get "very far" data, and the home page or the first comment page will not bother the database on the hard disk.
Delete and filter
We can use Lrem to delete comments.
You can put it on the list.
Leaderboard Related
Some usage scenarios for Redis