The thought of the second-kill concurrency in the Redis Realization Mall

Source: Internet
Author: User
Tags redis install redis

The full code is too long, here's a thought.

1: Before the start of the kill activity, the SKU and inventory of the item are credited to Redis

Redistemplate.expire (sku,25,timeunit.hours of goods); Cache 24 hours with the unique identity of the product as key

2: Add a counter to the product order method, the commodity SKU is key, the counter is atomic, there is no concurrency problem

Long Count = Redistemplate.opsforvalue (). Increment (commodity suk, 1);

3: When the order is submitted, the inventory of the SKU is obtained from Redis, and the count comparison in the counter, if it is greater than or equal to count, indicates that the seconds are dead

4: Synchronizing inventory to the database


If you do not know how to install Redis, you can refer to the previous article

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.