(clients, options)
| 117 | // `options` object. Properties of the Redlock object should NOT be changed after it is first |
| 118 | // used, as doing so could have unintended consequences for live locks. |
| 119 | function Redlock(clients, options) { |
| 120 | // set default options |
| 121 | options = options || {}; |
| 122 | this.driftFactor = typeof options.driftFactor === 'number' ? options.driftFactor : defaults.driftFactor; |
| 123 | this.retryCount = typeof options.retryCount === 'number' ? options.retryCount : defaults.retryCount; |
| 124 | this.retryDelay = typeof options.retryDelay === 'number' ? options.retryDelay : defaults.retryDelay; |
| 125 | this.retryJitter = typeof options.retryJitter === 'number' ? options.retryJitter : defaults.retryJitter; |
| 126 | this.lockScript = typeof options.lockScript === 'function' ? options.lockScript(lockScript) : lockScript; |
| 127 | this.unlockScript = typeof options.unlockScript === 'function' ? options.unlockScript(unlockScript) : unlockScript; |
| 128 | this.extendScript = typeof options.extendScript === 'function' ? options.extendScript(extendScript) : extendScript; |
| 129 | // set the redis servers from additional arguments |
| 130 | this.servers = clients; |
| 131 | if(this.servers.length === 0) |
| 132 | throw new Error('Redlock must be instantiated with at least one redis server.'); |
| 133 | |
| 134 | this.scripts = { |
| 135 | lockScript: { value: this.lockScript, hash: this._hashScript(this.lockScript) }, |
| 136 | unlockScript: { value: this.unlockScript, hash: this._hashScript(this.unlockScript) }, |
| 137 | extendScript: { value: this.extendScript, hash: this._hashScript(this.extendScript) }, |
| 138 | }; |
| 139 | } |
| 140 | |
| 141 | // Inherit all the EventEmitter methods, like `on`, and `off` |
| 142 | util.inherits(Redlock, EventEmitter); |
nothing calls this directly
no outgoing calls
no test coverage detected