Lock mechanism. Before the code enters the operation, check whether the operation is locked. If it is locked, interrupt the operation. Otherwise, proceed to the next operation. The first step is to lock the operation, then execute the code. After executing the code, don't forget to unlock the operation lock. Otherwise, you won’t be able to carry out the execution.
There are many locking codes, and the one given above is one of them. Redismemcachecache files can be used. If the concurrency of operations is relatively high, it is recommended to use redis like the one above. (In fact, it is to use the string data type to assign a value to the lock key {lock}, and when unlocking, the value of the key will be cleared or assigned a value of 0)
Lock mechanism. Before the code enters the operation, check whether the operation is locked. If it is locked, interrupt the operation. Otherwise, proceed to the next operation. The first step is to lock the operation, then execute the code. After executing the code, don't forget to unlock the operation lock. Otherwise, you won’t be able to carry out the execution.
There are many locking codes, and the one given above is one of them. Redismemcachecache files can be used. If the concurrency of operations is relatively high, it is recommended to use redis like the one above. (In fact, it is to use the string data type to assign a value to the lock key {lock}, and when unlocking, the value of the key will be cleared or assigned a value of 0)
The redis "lock" mentioned by the poster is of course feasible
In addition, can a unique ID be set for the queried data? This is double verification