Reputation: 22535
Is there a possible race condition with Redis' ltrim and rpush?
For instance, suppose my redis list has these items: [1, 2, 3, 4, 5]
And I call ltrim list 4 -1
This basically should slice the list to just [5]
BUT let's say: a millisecond after ltrim has started and before ltrim is finished, another thread is pushing items to the list:
rpush list 6
rpush list 7
When both the 2 rpushes, and ltrims are finished, will the resulting list consist of [5, 6, 7]?
could it possibly be just [5]? In other words, is there a possibility of a race condition where ltrim does something like creating a temporary list with [5], and overwrites [5,6,7] with [5] after the 2 rpushes are done?
Upvotes: 0
Views: 327
Reputation: 19042
Short answer: No, because commands are atomic.
Honest answer: I don't think so because I think operations are atomic; however, the website doesn't explicitly state that they are atomic so I'm only 99.99999999% sure that they are.
Logical answer: Redis is single-threaded, so there are no other threads that could preempt the ltrim command. For a race condition to occur in a single threaded application it would have to explicitly jump out of the ltrim operation before it's done and start doing something else, which doesn't make much sense.
Upvotes: 4