Lock
Classes
- LockHandle
The LockHandle is returned from the InMemoryLock and acts as interface to the actual lock
- InMemoryLock
The InMemoryLock is represents a per process lock
- Lock
- LockHandle
The LockHandle is returned from the RedisLock and acts as interface to the actual lock.
- RedisLock
The RedisLock is represents lock shareable between processes.
- LockHandle
The LockHandle is returned from the InMemoryLock and acts as interface to the actual lock
- InMemoryLock
The InMemoryLock is represents a per process lock
- Lock
- LockHandle
The LockHandle is returned from the RedisLock and acts as interface to the actual lock.
- RedisLock
The RedisLock is represents lock shareable between processes.
Functions
- create(options)
Creates a lock of a specifed type
- wait()
A promise version of setTimeout
- create(options)
Creates a lock of a specifed type
- wait()
A promise version of setTimeout
LockHandle
The LockHandle is returned from the InMemoryLock and acts as interface to the actual lock
Kind: global class
- LockHandle
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
InMemoryLock
The InMemoryLock is represents a per process lock
Kind: global class
new InMemoryLock(options)
Creates an InMemoryLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.retry | int | the number of times to retry to claim the lock |
options.delay | int | the delay in milliseconds between attempts to claim the lock |
new InMemoryLock(options)
Creates an InMemoryLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.retry | int | the number of times to retry to claim the lock |
options.delay | int | the delay in milliseconds between attempts to claim the lock |
Promise
inMemoryLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of InMemoryLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
inMemoryLock.obtainLock(key, options, count)
This will attempt to obtain a lock until the count exceeds the max retries.
Kind: instance method of InMemoryLock
Param | Type | Description |
---|---|---|
key | string | the name of the lock |
options | object | the options object |
options.ttl | int | the time to keep the lock in milliseconds |
count | int | the number of times the obtain lock has been attempted |
Promise
inMemoryLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of InMemoryLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
inMemoryLock.obtainLock(key, options, count)
This will attempt to obtain a lock until the count exceeds the max retries.
Kind: instance method of InMemoryLock
Param | Type | Description |
---|---|---|
key | string | the name of the lock |
options | object | the options object |
options.ttl | int | the time to keep the lock in milliseconds |
count | int | the number of times the obtain lock has been attempted |
Lock
Kind: global class
- Lock
- new Lock()
- new Lock()
- .stop() ⇒
Promise
- .getKey(namespace)
- .lock(key, options) ⇒
Promise
- .lockNs(key, options)
- .stop() ⇒
Promise
- .getKey(namespace)
- .lock(key, options) ⇒
Promise
- .lockNs(key, options)
new Lock()
Creates a Cache object
Param | Type | Description |
---|---|---|
options.namespace | string | the namespace string to use in the xxxNs methods. Defaults to 'app' |
new Lock()
Creates a Cache object
Param | Type | Description |
---|---|---|
options.namespace | string | the namespace string to use in the xxxNs methods. Defaults to 'app' |
Promise
lock.stop() ⇒ Destroys all resources
Kind: instance method of Lock
lock.getKey(namespace)
Returns the actual key to use. This will combine the namespace + ':' + key if a namespace is available.
Kind: instance method of Lock
Oaram: string
key an key to prefix with namespace
Param | Type | Default | Description |
---|---|---|---|
namespace | string | null | if supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used. |
Promise
lock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of Lock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
lock.lockNs(key, options)
Locks on the namespace:key
Kind: instance method of Lock
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds * @return {Promise} a Promise that will resolve with a Lock Handle. The LockHandle has two methods: unlock : Release the lock, returns a Promise extend( timeMilliseconds ) : extend the lock for a time from now. |
Promise
lock.stop() ⇒ Destroys all resources
Kind: instance method of Lock
lock.getKey(namespace)
Returns the actual key to use. This will combine the namespace + ':' + key if a namespace is available.
Kind: instance method of Lock
Oaram: string
key an key to prefix with namespace
Param | Type | Default | Description |
---|---|---|---|
namespace | string | null | if supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used. |
Promise
lock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of Lock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
lock.lockNs(key, options)
Locks on the namespace:key
Kind: instance method of Lock
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds * @return {Promise} a Promise that will resolve with a Lock Handle. The LockHandle has two methods: unlock : Release the lock, returns a Promise extend( timeMilliseconds ) : extend the lock for a time from now. |
LockHandle
The LockHandle is returned from the RedisLock and acts as interface to the actual lock.
Kind: global class
- LockHandle
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
RedisLock
The RedisLock is represents lock shareable between processes.
Kind: global class
- RedisLock
- new RedisLock(options)
- new RedisLock(options)
- .stop() ⇒
Promise
- .lock(key, options) ⇒
Promise
- .stop() ⇒
Promise
- .lock(key, options) ⇒
Promise
new RedisLock(options)
Creates an RedisLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.connection | object | the redis connection object |
options.lockOptions | object | the options for the lock |
options.lockOptions.retryCount | int | the number of times to try to claim the lock. If negative one, this will try forever. |
options.lockOptions.retryDelay | int | the time in ms between attempts |
options.lockOptions.retryJitter | int | the max time in ms randomly added to retries |
options.lockOptions.driftFactor | number | the expected clock drift in ms |
new RedisLock(options)
Creates an RedisLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.connection | object | the redis connection object |
options.lockOptions | object | the options for the lock |
options.lockOptions.retryCount | int | the number of times to try to claim the lock. If negative one, this will try forever. |
options.lockOptions.retryDelay | int | the time in ms between attempts |
options.lockOptions.retryJitter | int | the max time in ms randomly added to retries |
options.lockOptions.driftFactor | number | the expected clock drift in ms |
Promise
redisLock.stop() ⇒ Destroys all resources
Kind: instance method of RedisLock
Promise
redisLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of RedisLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
Promise
redisLock.stop() ⇒ Destroys all resources
Kind: instance method of RedisLock
Promise
redisLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of RedisLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
LockHandle
The LockHandle is returned from the InMemoryLock and acts as interface to the actual lock
Kind: global class
- LockHandle
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
InMemoryLock
The InMemoryLock is represents a per process lock
Kind: global class
new InMemoryLock(options)
Creates an InMemoryLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.retry | int | the number of times to retry to claim the lock |
options.delay | int | the delay in milliseconds between attempts to claim the lock |
new InMemoryLock(options)
Creates an InMemoryLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.retry | int | the number of times to retry to claim the lock |
options.delay | int | the delay in milliseconds between attempts to claim the lock |
Promise
inMemoryLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of InMemoryLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
inMemoryLock.obtainLock(key, options, count)
This will attempt to obtain a lock until the count exceeds the max retries.
Kind: instance method of InMemoryLock
Param | Type | Description |
---|---|---|
key | string | the name of the lock |
options | object | the options object |
options.ttl | int | the time to keep the lock in milliseconds |
count | int | the number of times the obtain lock has been attempted |
Promise
inMemoryLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of InMemoryLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
inMemoryLock.obtainLock(key, options, count)
This will attempt to obtain a lock until the count exceeds the max retries.
Kind: instance method of InMemoryLock
Param | Type | Description |
---|---|---|
key | string | the name of the lock |
options | object | the options object |
options.ttl | int | the time to keep the lock in milliseconds |
count | int | the number of times the obtain lock has been attempted |
Lock
Kind: global class
- Lock
- new Lock()
- new Lock()
- .stop() ⇒
Promise
- .getKey(namespace)
- .lock(key, options) ⇒
Promise
- .lockNs(key, options)
- .stop() ⇒
Promise
- .getKey(namespace)
- .lock(key, options) ⇒
Promise
- .lockNs(key, options)
new Lock()
Creates a Cache object
Param | Type | Description |
---|---|---|
options.namespace | string | the namespace string to use in the xxxNs methods. Defaults to 'app' |
new Lock()
Creates a Cache object
Param | Type | Description |
---|---|---|
options.namespace | string | the namespace string to use in the xxxNs methods. Defaults to 'app' |
Promise
lock.stop() ⇒ Destroys all resources
Kind: instance method of Lock
lock.getKey(namespace)
Returns the actual key to use. This will combine the namespace + ':' + key if a namespace is available.
Kind: instance method of Lock
Oaram: string
key an key to prefix with namespace
Param | Type | Default | Description |
---|---|---|---|
namespace | string | null | if supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used. |
Promise
lock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of Lock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
lock.lockNs(key, options)
Locks on the namespace:key
Kind: instance method of Lock
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds * @return {Promise} a Promise that will resolve with a Lock Handle. The LockHandle has two methods: unlock : Release the lock, returns a Promise extend( timeMilliseconds ) : extend the lock for a time from now. |
Promise
lock.stop() ⇒ Destroys all resources
Kind: instance method of Lock
lock.getKey(namespace)
Returns the actual key to use. This will combine the namespace + ':' + key if a namespace is available.
Kind: instance method of Lock
Oaram: string
key an key to prefix with namespace
Param | Type | Default | Description |
---|---|---|---|
namespace | string | null | if supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used. |
Promise
lock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of Lock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
lock.lockNs(key, options)
Locks on the namespace:key
Kind: instance method of Lock
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds * @return {Promise} a Promise that will resolve with a Lock Handle. The LockHandle has two methods: unlock : Release the lock, returns a Promise extend( timeMilliseconds ) : extend the lock for a time from now. |
LockHandle
The LockHandle is returned from the RedisLock and acts as interface to the actual lock.
Kind: global class
- LockHandle
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- new LockHandle(memLock, key, ttl)
- new LockHandle(lock)
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
- .unlock() ⇒
Promise
- .extend(time) ⇒
Promise
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
new LockHandle(memLock, key, ttl)
Creates the lock handle
Param | Type | Description |
---|---|---|
memLock | InMemoryLock | the memory lock |
key | string | the key to lock |
ttl | int | the time to keep the lock |
new LockHandle(lock)
Creates the lock handle
Param | Type | Description |
---|---|---|
lock | lock | the RedLock lock object |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
Promise
lockHandle.unlock() ⇒ Release the lock.
Kind: instance method of LockHandle
Returns: Promise
- a Promise to release the lock
Promise
lockHandle.extend(time) ⇒ Extend the lock's time
Kind: instance method of LockHandle
Returns: Promise
- a Promise that returns this Lock object
Param | Type | Description |
---|---|---|
time | int | the time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time |
RedisLock
The RedisLock is represents lock shareable between processes.
Kind: global class
- RedisLock
- new RedisLock(options)
- new RedisLock(options)
- .stop() ⇒
Promise
- .lock(key, options) ⇒
Promise
- .stop() ⇒
Promise
- .lock(key, options) ⇒
Promise
new RedisLock(options)
Creates an RedisLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.connection | object | the redis connection object |
options.lockOptions | object | the options for the lock |
options.lockOptions.retryCount | int | the number of times to try to claim the lock. If negative one, this will try forever. |
options.lockOptions.retryDelay | int | the time in ms between attempts |
options.lockOptions.retryJitter | int | the max time in ms randomly added to retries |
options.lockOptions.driftFactor | number | the expected clock drift in ms |
new RedisLock(options)
Creates an RedisLock.
Param | Type | Description |
---|---|---|
options | object | the options for the lock |
options.namespace | string | the namespace used in lockNS. |
options.connection | object | the redis connection object |
options.lockOptions | object | the options for the lock |
options.lockOptions.retryCount | int | the number of times to try to claim the lock. If negative one, this will try forever. |
options.lockOptions.retryDelay | int | the time in ms between attempts |
options.lockOptions.retryJitter | int | the max time in ms randomly added to retries |
options.lockOptions.driftFactor | number | the expected clock drift in ms |
Promise
redisLock.stop() ⇒ Destroys all resources
Kind: instance method of RedisLock
Promise
redisLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of RedisLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
Promise
redisLock.stop() ⇒ Destroys all resources
Kind: instance method of RedisLock
Promise
redisLock.lock(key, options) ⇒ Locks on the key. This will not auto-prefix the key with the namespace. To auto prefix the key, use lockNs( key )
Kind: instance method of RedisLock
Returns: Promise
- a Promise that will resolve with a Lock Handle.
The LockHandle has two methods:
unlock : Release the lock, returns a Promise
extend( timeMilliseconds ) : extend the lock for a time from now.
Param | Type | Description | |
---|---|---|---|
key | string | the key to lookup | |
options | object \ | int | either a time in milliseconds to keep the lock or and object containing the options for the lock |
options.ttl | int | time to keep lock in milliseconds |
create(options)
Creates a lock of a specifed type
Kind: global function
Param | Type | Description |
---|---|---|
options | object | the lock options |
options.type | string | the type of lock to make. If unrecognized, this will throw an exception. Possible values: 'redis', 'inMemory' |
options.namespace | string | a string that will prepended (with a ':') to all lock keys when accessing the lock using lockNS. The resulting key will be namespace:key |
options.lockConfig | object | This can be an object, JSON or reference to a json/js file. If defined, it will be expanded and merged with the other options like prefix. This allows the lock type to be controlled by an environment variable or file. |
wait()
A promise version of setTimeout
create(options)
Creates a lock of a specifed type
Kind: global function
Param | Type | Description |
---|---|---|
options | object | the lock options |
options.type | string | the type of lock to make. If unrecognized, this will throw an exception. Possible values: 'redis', 'inMemory' |
options.namespace | string | a string that will prepended (with a ':') to all lock keys when accessing the lock using lockNS. The resulting key will be namespace:key |
options.lockConfig | object | This can be an object, JSON or reference to a json/js file. If defined, it will be expanded and merged with the other options like prefix. This allows the lock type to be controlled by an environment variable or file. |
wait()
A promise version of setTimeout
Kind: global function