I would like to ask, for example, when to insert a database if redis cache is used to make a highly concurrent flash sale activity.

I would like to ask, for example, when to make a highly concurrent flash sale activity if redis cache is used to insert the database
for example, when will the corresponding prizes be saved in the database when the activity is in progress?

May.23,2022

you can write mysql asynchronously with queue consumption. Each time the redis is written, a message is sent to the queue. After the consumer gets the message, it gets the order information through redis and writes it to mysql.
can also set a schedule to run every few minutes, pull new orders in redis within a few minutes, and write them to mysql. However, you need to pay attention to the redis occupancy problem, which may block redis if the design is flawed.
at the same time, do a good job of persistence of redis, so as to avoid the loss of data without persistence after the crash of redis, so that the order does not match.


writes inventory to the queue, and each request takes a value from the queue. If there is a value, it is processed as a normal request. For example, if you set up an inventory of 100, there are only 100 requests to the database.
100 requests are not large and when a request comes, php-fpm creates a process to receive the request until the request is processed. Php-fpm can send many people (processes) at the same time without interfering with each other.
the larger the server processor and memory, the more people php-fpm can dispatch. This doesn't need php programmers to worry about. Of course, under certain circumstances of processor and memory, the smaller the workload of each person (the better the programming), the more people php-fpm can send at the same time.


1. Redis is used to quickly determine whether items that are killed in seconds are still in stock.
2. Limit the current by judging the result of redis data, so as to reduce the pressure on the server.
the amount of data persisted to the database by 3.redis is very small, as long as the database is operated normally.

Menu