Skip to content

Commit

Permalink
Merge pull request #40 from max0d41/master
Browse files Browse the repository at this point in the history
Allow unlimited retries to acquire the lock with `retryCount=-1`.
  • Loading branch information
mike-marcacci committed Mar 18, 2018
2 parents f8c696a + d80c901 commit 479e3bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -34,6 +34,8 @@ Redlock cannot tell you *with certainty* if a resource is currently locked. For

That said, for many tasks it's sufficient to attempt a lock with `retryCount=0`, and treat a failure as the resource being "locked" or (more correctly) "unavailable",

With `retryCount=-1` there will be unlimited retries until the lock is aquired.


Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "redlock",
"version": "3.1.1",
"version": "3.1.2",
"description": "A node.js redlock implementation for distributed redis locks",
"main": "redlock.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion redlock.js
Expand Up @@ -335,7 +335,7 @@ Redlock.prototype._lock = function _lock(resource, value, ttl, callback) {
return lock.unlock(function(){

// RETRY
if(attempts <= self.retryCount)
if(self.retryCount === -1 || attempts <= self.retryCount)
return setTimeout(attempt, Math.max(0, self.retryDelay + Math.floor((Math.random() * 2 - 1) * self.retryJitter)));

// FAILED
Expand Down

0 comments on commit 479e3bc

Please sign in to comment.