-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
'use strict'; | ||
|
||
var util = require('util'); | ||
var Promise = require('bluebird'); | ||
var util = require('util'); | ||
var Promise = require('bluebird'); | ||
var EventEmitter = require('events'); | ||
|
||
// constants | ||
var unlockScript = 'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end'; | ||
|
@@ -71,13 +72,17 @@ function Redlock(clients, 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; | ||
|
||
// set the redis servers from additional arguments | ||
this.servers = clients; | ||
if(this.servers.length === 0) | ||
throw new Error('Redlock must be instantiated with at least one redis server.'); | ||
} | ||
|
||
// Inherit all the EventEmitter methods, like `on`, and `off` | ||
util.inherits(Redlock, EventEmitter); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mike-marcacci
Author
Owner
|
||
|
||
|
||
// Attach a reference to LockError per issue #7, which allows the application to use instanceof | ||
// to destinguish between error types. | ||
Redlock.LockError = LockError; | ||
|
@@ -148,6 +153,7 @@ Redlock.prototype.unlock = function unlock(lock, callback) { | |
}); | ||
|
||
function loop(err, response) { | ||
if(err) self.emit('clientError', err); | ||
if(waiting-- > 1) return; | ||
return resolve(); | ||
} | ||
|
@@ -215,7 +221,7 @@ Redlock.prototype.extend = function extend(lock, ttl, callback) { | |
Redlock.prototype._lock = function _lock(resource, value, ttl, callback) { | ||
var self = this; | ||
return new Promise(function(resolve, reject) { | ||
var request; | ||
var request; | ||
|
||
// the number of times we have attempted this lock | ||
var attempts = 0; | ||
|
@@ -252,6 +258,7 @@ Redlock.prototype._lock = function _lock(resource, value, ttl, callback) { | |
var waiting = self.servers.length; | ||
|
||
function loop(err, response) { | ||
if(err) self.emit('clientError', err); | ||
if(response) votes++; | ||
if(waiting-- > 1) return; | ||
|
||
|
Getting
Uncaught exception TypeError: Object prototype may only be an Object or null
I20150910-20:04:12.307(-4)? at Function.create (native)
I20150910-20:04:12.307(-4)? at Object.exports.inherits (util.js:556:27)
I20150910-20:04:12.307(-4)? at Object. (/Users/jperl/dev/dispatch/meteor-cache/.meteor/local/isopacks/dispatch_cache-crud/npm/node_modules/redlock/redlock.js:83:6)