Some usage scenarios for Redis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.