How to realize the operation of buying tickets in cinemas to prevent the phenomenon of buying more than one ticket?

recently, a project is a theater ticket management system, but the ticket module does not know how to implement it. At first, it uses the transaction and locking mechanism of MySQL database, but there are still some problems. Finally, I think about whether we can use Redis message queue, but I don"t know how to implement it. I hope which boss can give some ideas or opinions. I"m much obliged.

Mar.02,2021
How is

12306 implemented? check the database before each purchase to see if the status is correct. If the status is right, I'll let you buy it. If it is not correct, it will show that it is booked


row-level lock will not be OK


use redis's incr , decr , incrby to control the increase and decrease of inventory, which is not so complicated.

< hr >

to put it simply, when inventory is produced, Synchronize in redis also produces inventory. Users only need to add or subtract inventory in redis after the purchase request, execute redis transaction with Synchronize after successful redis operation, or introduce message queue to execute db transaction asynchronously. The reason why you can use redis to solve concurrent oversold is that redis is a single-process, single-threaded Synchronize operation, so you can design it at will, and so is the second kill operation.

Menu