CodePark/ questions / What Redis is & how it works
START PRACTICINGPRACTICE
Backend question · Redis & caching › What Redis is & how it works

Key counter holds 10. Two clients send INCR counter at exactly the same moment. What is the value afterwards?

Always 12

Redis runs commands one at a time. So the two INCR calls run one after the other, and the second one sees the result of the first. The value goes 10 → 11 → 12.

"Either 11 or 12, depending on timing" is wrong. A
lost update happens when application code does GET and then SET: both clients read 10 and both write 11. That cannot happen inside a single Redis command. "11, because the second command is rejected" and "An error, because the key is locked by the first client" are also wrong: Redis does not lock keys or reject the second command. It just queues it.