reids has DECR (atomic decrement), and memcache also has the decrement function. The difference between them is that when redis’s atomic decrement reaches 0, it will become a negative number, while memcache’s will always be 0
Do not check the lock, pass it directly, but check the version number after passing it, and do not operate it correctly, otherwise roll back (requires transaction support)
One problem is that maybe users in orders 2 and 3 didn’t get it, but users in order 4 and 5 got it (in this case, you’ll know after you write a demo and test it)
reids has DECR (atomic decrement), and memcache also has the decrement function. The difference between them is that when redis’s atomic decrement reaches 0, it will become a negative number, while memcache’s will always be 0
No. It will become -1, I'm afraid you have to make your own judgment.
Optimistic lock solution
Do not check the lock, pass it directly, but check the version number after passing it, and do not operate it correctly, otherwise roll back (requires transaction support)
One problem is that maybe users in orders 2 and 3 didn’t get it, but users in order 4 and 5 got it (in this case, you’ll know after you write a demo and test it)