可以说我有这张桌子:
| id | fruit | status
--------------------------------
| 1 | banana | good
| 2 | apple | good
User send request to server -> server send a response with the fruit -> server updated status to 'consumed'
Imagine the following scenario in which two users send a request at the same time saying that they will consume
a fruit that has good
status
How to prevent both users from having a 'banana
' answer?
You should use a table lock , http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html