Leverege Platform

Leverege Platform

  • Overview
  • JSDocs
  • REST API
  • Help

›JSDoc

JSDoc

  • Home
  • API Server
  • API Attributes
  • Api Patch Ops
  • API Redux
  • Array Util
  • Base62 Util
  • Cache
  • Cluster Manager
  • Data Store
  • Exit
  • Factory
  • Limit
  • Lock
  • Message Queue
  • Messages
  • Path
  • Permissions
  • Reasoner
  • String Util
  • UI Active Theme
  • UI Elements
  • UI Linear View Elements
  • UI Mapbox Elements
  • Validator

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

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

new LockHandle(memLock, key, ttl)

Creates the lock handle

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe 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

  • InMemoryLock
    • new InMemoryLock(options)
    • new InMemoryLock(options)
    • .lock(key, options) ⇒ Promise
    • .obtainLock(key, options, count)
    • .lock(key, options) ⇒ Promise
    • .obtainLock(key, options, count)

new InMemoryLock(options)

Creates an InMemoryLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.retryintthe number of times to retry to claim the lock
options.delayintthe delay in milliseconds between attempts to claim the lock

new InMemoryLock(options)

Creates an InMemoryLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.retryintthe number of times to retry to claim the lock
options.delayintthe delay in milliseconds between attempts to claim the lock

inMemoryLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
keystringthe name of the lock
optionsobjectthe options object
options.ttlintthe time to keep the lock in milliseconds
countintthe number of times the obtain lock has been attempted

inMemoryLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
keystringthe name of the lock
optionsobjectthe options object
options.ttlintthe time to keep the lock in milliseconds
countintthe 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

ParamTypeDescription
options.namespacestringthe namespace string to use in the xxxNs methods. Defaults to 'app'

new Lock()

Creates a Cache object

ParamTypeDescription
options.namespacestringthe namespace string to use in the xxxNs methods. Defaults to 'app'

lock.stop() ⇒ Promise

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

ParamTypeDefaultDescription
namespacestringnullif supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used.

lock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

lock.lockNs(key, options)

Locks on the namespace:key

Kind: instance method of Lock

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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.

lock.stop() ⇒ Promise

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

ParamTypeDefaultDescription
namespacestringnullif supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used.

lock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

lock.lockNs(key, options)

Locks on the namespace:key

Kind: instance method of Lock

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

new LockHandle(memLock, key, ttl)

Creates the lock handle

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe 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.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.connectionobjectthe redis connection object
options.lockOptionsobjectthe options for the lock
options.lockOptions.retryCountintthe number of times to try to claim the lock. If negative one, this will try forever.
options.lockOptions.retryDelayintthe time in ms between attempts
options.lockOptions.retryJitterintthe max time in ms randomly added to retries
options.lockOptions.driftFactornumberthe expected clock drift in ms

new RedisLock(options)

Creates an RedisLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.connectionobjectthe redis connection object
options.lockOptionsobjectthe options for the lock
options.lockOptions.retryCountintthe number of times to try to claim the lock. If negative one, this will try forever.
options.lockOptions.retryDelayintthe time in ms between attempts
options.lockOptions.retryJitterintthe max time in ms randomly added to retries
options.lockOptions.driftFactornumberthe expected clock drift in ms

redisLock.stop() ⇒ Promise

Destroys all resources

Kind: instance method of RedisLock

redisLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

redisLock.stop() ⇒ Promise

Destroys all resources

Kind: instance method of RedisLock

redisLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

new LockHandle(memLock, key, ttl)

Creates the lock handle

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe 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

  • InMemoryLock
    • new InMemoryLock(options)
    • new InMemoryLock(options)
    • .lock(key, options) ⇒ Promise
    • .obtainLock(key, options, count)
    • .lock(key, options) ⇒ Promise
    • .obtainLock(key, options, count)

new InMemoryLock(options)

Creates an InMemoryLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.retryintthe number of times to retry to claim the lock
options.delayintthe delay in milliseconds between attempts to claim the lock

new InMemoryLock(options)

Creates an InMemoryLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.retryintthe number of times to retry to claim the lock
options.delayintthe delay in milliseconds between attempts to claim the lock

inMemoryLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
keystringthe name of the lock
optionsobjectthe options object
options.ttlintthe time to keep the lock in milliseconds
countintthe number of times the obtain lock has been attempted

inMemoryLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
keystringthe name of the lock
optionsobjectthe options object
options.ttlintthe time to keep the lock in milliseconds
countintthe 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

ParamTypeDescription
options.namespacestringthe namespace string to use in the xxxNs methods. Defaults to 'app'

new Lock()

Creates a Cache object

ParamTypeDescription
options.namespacestringthe namespace string to use in the xxxNs methods. Defaults to 'app'

lock.stop() ⇒ Promise

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

ParamTypeDefaultDescription
namespacestringnullif supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used.

lock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

lock.lockNs(key, options)

Locks on the namespace:key

Kind: instance method of Lock

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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.

lock.stop() ⇒ Promise

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

ParamTypeDefaultDescription
namespacestringnullif supplied, this will be used as the namespace. Otherwise, the namespace supplied in the options will be used.

lock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

lock.lockNs(key, options)

Locks on the namespace:key

Kind: instance method of Lock

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime 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

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

new LockHandle(memLock, key, ttl)

Creates the lock handle

ParamTypeDescription
memLockInMemoryLockthe memory lock
keystringthe key to lock
ttlintthe time to keep the lock

new LockHandle(lock)

Creates the lock handle

ParamTypeDescription
locklockthe RedLock lock object

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe time in milliseconds to set the lock. This will set the lock's expiration to be Date.now() + time

lockHandle.unlock() ⇒ Promise

Release the lock.

Kind: instance method of LockHandle
Returns: Promise - a Promise to release the lock

lockHandle.extend(time) ⇒ Promise

Extend the lock's time

Kind: instance method of LockHandle
Returns: Promise - a Promise that returns this Lock object

ParamTypeDescription
timeintthe 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.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.connectionobjectthe redis connection object
options.lockOptionsobjectthe options for the lock
options.lockOptions.retryCountintthe number of times to try to claim the lock. If negative one, this will try forever.
options.lockOptions.retryDelayintthe time in ms between attempts
options.lockOptions.retryJitterintthe max time in ms randomly added to retries
options.lockOptions.driftFactornumberthe expected clock drift in ms

new RedisLock(options)

Creates an RedisLock.

ParamTypeDescription
optionsobjectthe options for the lock
options.namespacestringthe namespace used in lockNS.
options.connectionobjectthe redis connection object
options.lockOptionsobjectthe options for the lock
options.lockOptions.retryCountintthe number of times to try to claim the lock. If negative one, this will try forever.
options.lockOptions.retryDelayintthe time in ms between attempts
options.lockOptions.retryJitterintthe max time in ms randomly added to retries
options.lockOptions.driftFactornumberthe expected clock drift in ms

redisLock.stop() ⇒ Promise

Destroys all resources

Kind: instance method of RedisLock

redisLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

redisLock.stop() ⇒ Promise

Destroys all resources

Kind: instance method of RedisLock

redisLock.lock(key, options) ⇒ Promise

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.

ParamTypeDescription
keystringthe key to lookup
optionsobject \inteither a time in milliseconds to keep the lock or and object containing the options for the lock
options.ttlinttime to keep lock in milliseconds

create(options)

Creates a lock of a specifed type

Kind: global function

ParamTypeDescription
optionsobjectthe lock options
options.typestringthe type of lock to make. If unrecognized, this will throw an exception. Possible values: 'redis', 'inMemory'
options.namespacestringa string that will prepended (with a ':') to all lock keys when accessing the lock using lockNS. The resulting key will be namespace:key
options.lockConfigobjectThis 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

create(options)

Creates a lock of a specifed type

Kind: global function

ParamTypeDescription
optionsobjectthe lock options
options.typestringthe type of lock to make. If unrecognized, this will throw an exception. Possible values: 'redis', 'inMemory'
options.namespacestringa string that will prepended (with a ':') to all lock keys when accessing the lock using lockNS. The resulting key will be namespace:key
options.lockConfigobjectThis 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

← LimitMessage Queue →
  • Classes
  • Functions
  • LockHandle
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
  • InMemoryLock
    • new InMemoryLock(options)
    • new InMemoryLock(options)
    • inMemoryLock.lock(key, options) ⇒ Promise
    • inMemoryLock.obtainLock(key, options, count)
    • inMemoryLock.lock(key, options) ⇒ Promise
    • inMemoryLock.obtainLock(key, options, count)
  • Lock
    • new Lock()
    • new Lock()
    • lock.stop() ⇒ Promise
    • lock.getKey(namespace)
    • lock.lock(key, options) ⇒ Promise
    • lock.lockNs(key, options)
    • lock.stop() ⇒ Promise
    • lock.getKey(namespace)
    • lock.lock(key, options) ⇒ Promise
    • lock.lockNs(key, options)
  • LockHandle
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
  • RedisLock
    • new RedisLock(options)
    • new RedisLock(options)
    • redisLock.stop() ⇒ Promise
    • redisLock.lock(key, options) ⇒ Promise
    • redisLock.stop() ⇒ Promise
    • redisLock.lock(key, options) ⇒ Promise
  • LockHandle
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
  • InMemoryLock
    • new InMemoryLock(options)
    • new InMemoryLock(options)
    • inMemoryLock.lock(key, options) ⇒ Promise
    • inMemoryLock.obtainLock(key, options, count)
    • inMemoryLock.lock(key, options) ⇒ Promise
    • inMemoryLock.obtainLock(key, options, count)
  • Lock
    • new Lock()
    • new Lock()
    • lock.stop() ⇒ Promise
    • lock.getKey(namespace)
    • lock.lock(key, options) ⇒ Promise
    • lock.lockNs(key, options)
    • lock.stop() ⇒ Promise
    • lock.getKey(namespace)
    • lock.lock(key, options) ⇒ Promise
    • lock.lockNs(key, options)
  • LockHandle
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • new LockHandle(memLock, key, ttl)
    • new LockHandle(lock)
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
    • lockHandle.unlock() ⇒ Promise
    • lockHandle.extend(time) ⇒ Promise
  • RedisLock
    • new RedisLock(options)
    • new RedisLock(options)
    • redisLock.stop() ⇒ Promise
    • redisLock.lock(key, options) ⇒ Promise
    • redisLock.stop() ⇒ Promise
    • redisLock.lock(key, options) ⇒ Promise
  • create(options)
  • wait()
  • create(options)
  • wait()
Leverege Platform
Docs
Overview
Connect
FacebookLinkedInTwitter
Facebook Open Source