Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redlock

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redlock - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

2

package.json
{
"name": "redlock",
"version": "2.1.0",
"version": "2.1.1",
"description": "A node.js redlock implementation for distributed redis locks",

@@ -5,0 +5,0 @@ "main": "redlock.js",

@@ -15,3 +15,3 @@ [![npm version](https://badge.fury.io/js/redlock.svg)](https://www.npmjs.com/package/redlock)

###High-Availability Recommendations
### High-Availability Recommendations
- Use at least 3 independent servers or clusters

@@ -23,3 +23,3 @@ - Use an odd number of independent redis ***servers*** for most installations

###Using Cluster/Sentinel
### Using Cluster/Sentinel
It is completely possible to use a *single* redis cluster or sentinal configuration by passing one preconfigured client to redlock. While you do gain high availability and vastly increased throughput under this scheme, the failure modes are a bit different, and it becomes theoretically possible that a lock is acquired twice:

@@ -34,3 +34,3 @@

###How do I check if something is locked?
### How do I check if something is locked?
Redlock cannot tell you *with certainty* if a resource is currently locked. For example, if you are on the smaller side of a network partition you will fail to acquire a lock, but you don't know if the lock exists on the other side; all you know is that you can't guarantee exclusivity on yours.

@@ -70,6 +70,11 @@

// to lock a resource before erroring
retryCount: 3,
retryCount: 10,
// the time in ms between attempts
retryDelay: 200 // time in ms
retryDelay: 400, // time in ms
// the max time in ms randomly added to retries
// to improve performance under high contention
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
retryJitter: 400 // time in ms
}

@@ -102,3 +107,3 @@ );

###Locking & Unocking
### Locking & Unlocking

@@ -131,3 +136,3 @@ ```js

###Locking and Extending
### Locking and Extending

@@ -162,3 +167,3 @@ ```js

###Locking & Unocking
### Locking & Unlocking

@@ -193,3 +198,3 @@ ```js

###Locking and Extending
### Locking and Extending

@@ -221,3 +226,3 @@ ```js

###Locking & Unocking
### Locking & Unlocking

@@ -260,3 +265,3 @@ ```js

###Locking and Extending
### Locking and Extending

@@ -302,3 +307,3 @@ ```js

###`Redlock.lock(resource, ttl, ?callback)`
### `Redlock.lock(resource, ttl, ?callback)`
- `resource (string)` resource to be locked

@@ -311,3 +316,3 @@ - `ttl (number)` time in ms until the lock expires

###`Redlock.unlock(lock, ?callback)`
### `Redlock.unlock(lock, ?callback)`
- `lock (Lock)` lock to be released

@@ -318,3 +323,3 @@ - `callback (function)` callback returning:

###`Redlock.extend(lock, ttl, ?callback)`
### `Redlock.extend(lock, ttl, ?callback)`
- `lock (Lock)` lock to be extended

@@ -327,3 +332,3 @@ - `ttl (number)` time in ms to extend the lock's expiration

###`Redlock.disposer(resource, ttl, ?unlockErrorHandler)`
### `Redlock.disposer(resource, ttl, ?unlockErrorHandler)`
- `resource (string)` resource to be locked

@@ -335,3 +340,3 @@ - `ttl (number)` time in ms to extend the lock's expiration

###`Lock.unlock(?callback)`
### `Lock.unlock(?callback)`
- `callback (function)` callback returning:

@@ -341,3 +346,3 @@ - `err (Error)`

###`Lock.extend(ttl, ?callback)`
### `Lock.extend(ttl, ?callback)`
- `ttl (number)` time in ms to extend the lock's expiration

@@ -344,0 +349,0 @@ - `callback (function)` callback returning:

@@ -21,4 +21,5 @@ 'use strict';

driftFactor: 0.01,
retryCount: 3,
retryDelay: 200
retryCount: 10,
retryDelay: 400,
retryJitter: 400
};

@@ -83,8 +84,9 @@

options = options || {};
this.driftFactor = typeof options.driftFactor === 'number' ? options.driftFactor : defaults.driftFactor;
this.retryCount = typeof options.retryCount === 'number' ? options.retryCount : defaults.retryCount;
this.retryDelay = typeof options.retryDelay === 'number' ? options.retryDelay : defaults.retryDelay;
this.lockScript = typeof options.lockScript === 'function' ? options.lockScript(lockScript) : lockScript;
this.unlockScript = typeof options.unlockScript === 'function' ? options.unlockScript(unlockScript) : unlockScript;
this.extendScript = typeof options.extendScript === 'function' ? options.extendScript(extendScript) : extendScript;
this.driftFactor = typeof options.driftFactor === 'number' ? options.driftFactor : defaults.driftFactor;
this.retryCount = typeof options.retryCount === 'number' ? options.retryCount : defaults.retryCount;
this.retryDelay = typeof options.retryDelay === 'number' ? options.retryDelay : defaults.retryDelay;
this.retryJitter = typeof options.retryJitter === 'number' ? options.retryJitter : defaults.retryJitter;
this.lockScript = typeof options.lockScript === 'function' ? options.lockScript(lockScript) : lockScript;
this.unlockScript = typeof options.unlockScript === 'function' ? options.unlockScript(unlockScript) : unlockScript;
this.extendScript = typeof options.extendScript === 'function' ? options.extendScript(extendScript) : extendScript;

@@ -157,7 +159,8 @@ // set the redis servers from additional arguments

var self = this;
// immediately invalidate the lock
lock.expiration = 0;
return new Promise(function(resolve, reject) {
// immediately invalidate the lock
lock.expiration = 0;
// the number of servers which have agreed to release this lock

@@ -317,3 +320,3 @@ var votes = 0;

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

@@ -320,0 +323,0 @@ // FAILED

@@ -14,3 +14,4 @@ 'use strict';

retryCount: 2,
retryDelay: 150
retryDelay: 150,
retryJitter: 0
});

@@ -35,3 +36,4 @@

retryCount: 2,
retryDelay: 150
retryDelay: 150,
retryJitter: 0
});

@@ -58,11 +60,11 @@ });

var opts = {
lockScript: function(lockScript) { return lockScript + "and 1"},
unlockScript: function(unlockScript) { return unlockScript + "and 2"},
extendScript: function(extendScript) { return extendScript + "and 3"}
}
lockScript: function(lockScript) { return lockScript + 'and 1'; },
unlockScript: function(unlockScript) { return unlockScript + 'and 2'; },
extendScript: function(extendScript) { return extendScript + 'and 3'; }
};
var customRedlock = new Redlock(clients, opts);
var i = 1;
assert.equal(customRedlock.lockScript, redlock.lockScript + "and " + i++);
assert.equal(customRedlock.unlockScript, redlock.unlockScript + "and " + i++);
assert.equal(customRedlock.extendScript, redlock.extendScript + "and " + i);
assert.equal(customRedlock.lockScript, redlock.lockScript + 'and ' + i++);
assert.equal(customRedlock.unlockScript, redlock.unlockScript + 'and ' + i++);
assert.equal(customRedlock.extendScript, redlock.extendScript + 'and ' + i);
});

@@ -109,3 +111,3 @@

two.unlock(done);
assert.equal(two.expiration, 0, 'Failed to immediately invalidate the lock.')
assert.equal(two.expiration, 0, 'Failed to immediately invalidate the lock.');
});

@@ -112,0 +114,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc