PHPz2017-04-24 09:12:21
The atomicity of the operation ensures that the operation cannot be divided again, and it is either completely executed or not executed completely.
You need to learn the principles of operating systems to be atomic. The time is a little long and it may not be accurate. Let me give a common example that has nothing to do with Redis.
There is a variable A=10, I want to add 5 to it. Then my "add 5" operation is divided into several steps:
There is another person who wants to add 3 to it. He doesn't know that I also want to operate the A variable. His "add 3" operation needs to be divided into several steps:
If our operations ("add 3" and "add 5") are not atomic, the instructions between each other will be arranged randomly, and the results are unpredictable. Maybe he has completed the writeback of +3 first. When I read it, it was already It is 13, so we got the correct result of +3 and then +5. It is also possible that he did not write back during the +3 operation. I happened to read 10, so when writing back, it may be 13 or 15.
If our operation is atomic, it can ensure that I cannot insert it when he performs the step of adding 3. I can only start my operation after he completes the operation, thus ensuring that the data is reliable.
PHPz2017-04-24 09:12:21
Similar to database transactions, a set of operations either succeeds or is not executed at all
PHPz2017-04-24 09:12:21
If you want to do it, just do it, if you don’t want to do it, don’t do it at all