Reputation: 4858
I read about Redis being used for mutual exclusion. Docs say the following :
Can somebody explain what condition can this simple implementation fail for achieving mutual exclusion.
For all the instance trying to do some critical work, do the following (pseudo code) :
while ( set keyForMutex anyValue nx == nil )
{
sleep ( 200 ms )
}
Finish up the critical task.
del keyForMutex
Upvotes: 0
Views: 450
Reputation: 49942
This wouldn't fail in achieving mutual exclusion, but it could over-succeed and deliver infinite exclusive exclusion if your code dies before it gets to deleting the key.
A possible solution is to expire the key after a generous timeout to allow the critical task to end.
Upvotes: 1