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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30e9b-2bd5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30e9b-2bd5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?