Closed nickminutello closed 11 years ago
For some reason, Github didn't give me notifications about your bug report, so I apologize for the delay in responding. Also, luckily for me, I also got a pull request to fix just this bug. I've merged it in now. The issue is #4.
I just noticed... we neednt retry if the lock has been deleted :
if(!existingLockTimestamp) {
// Wait, the lock doesn't exist!
// Someone must have called .del after we called .setnx but before .get.
// https://github.com/errorception/redis-lock/pull/4
return setTimeout(retry, 50);
}
We just need to move to the next step of trying to obtain the lock with a .getset (but make sure we have the right value to check if we got it)
What would be the right value to check? If we acquire the lock with .getset, we won't have existingLockTimestamp
set, so we won't know if we got the lock. .setnx would be the right command to use in such a scenario, hence the retry.
Or am I missing something?
I shall try to explain by annotating the code with some comments: