Mysql Voting question transaction

you need to check to see if the user has voted, and if so, the data is not inserted, and if not, the data is inserted. Under the condition of concurrency, it is possible for users to query not voting at the same time, and then result in the insertion of multiple pieces of data.

is there any good solution for such a situation?
as far as we know, transactions using databases do not lock select, so transactions may not solve such problems?
is it possible that only select for update is available? Is there any mainstream method

May.22,2021

user id and voting id can be combined with a unique key.

  

consider locking during concurrency. Voting should not be locked. Will lead to the defeat of the vote.
1. You can use the queue to add voting information to redis, and then Synchronize to mysql.
2. The number of votes is a separate int field. Just count.
3. Read from redis to mysql memory. However, if there is not such a large amount of concurrency, it is recommended that you do not need to do so.
the summary process is as follows:
php-> queue-> redis-> mysql <-redis <-php <-user

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-1b348b3-2bf26.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-1b348b3-2bf26.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?