Redis solves high concurrency problems, such as product flash sales and redis Products

Source: Internet
Author: User

Redis solves high concurrency problems, such as product flash sales and redis Products
Dreamer

Http://www.toutiao.com/a6450243964058140941? Tt_from = weixin & utm_campaign = client_share & app = news_article & utm_source = weixin & iid = 12675044243 & utm_medium = toutiao_android & wx1__count = 1

Redis is really a good technology. It can solve the website's concurrent traffic in a certain degree, such as flash sales and other activities...

The reason why redis can solve high concurrency is that it can directly access the memory. In the past, we used a database (hard disk), which improved the access efficiency and solved the pressure on the database server.

Why do we not choose memcache because memcache can only store strings, while redis has a wide variety of Storage types (such as string, LIST, and SET ), each value of memcache can only store 1 MB of data, and its storage resources are very limited, which consumes a lot of memory resources. redis can store 1 GB of data. The most important thing is that memcache is not as secure as redis, when the server fails or shuts down unexpectedly, redsi will back up the data in the memory to the hard disk, and all the data stored in memcache will be lost; this also shows that memcache is not suitable for databases and can be used for caching.

The following describes how to use apsaradb for redis to deal with flash sales:

The following program simulates 20 million people flooding into this page for seckilling. Only 500 people can be killed successfully. We put advanced users into the redis queue, when the number of users in the queue reaches 500, the user will go to the second kill end page. A random number is used to represent different users.

Here we can see that the id of the first user who succeeded in the second kill is 208522, the last user who succeeded in the second kill is 176260, and the total number of participants in the second kill is. (The reason is to verify the following accuracy ).

Next, we will take the 500 users who successfully killed the second from the queue and observe whether the first user and the last user are the same as the previous record values.

We can see that the first user ID retrieved from the second kill success queue is 208522, And the last user is 176260. The result is very accurate.

Redis's ability in Solving High concurrency is really good.

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.