Private
Readonly
attemptProtected
Readonly
loggerPrivate
Readonly
redisPrivate
Readonly
redisPrivate
Readonly
redisAcquires a lock on the requested identifier. The promise will resolve when the lock has been acquired.
Resource to acquire a lock on.
Private
createPrivate
getCreate a scoped Redis key for Read-Write locking.
A scoped Redis key that allows cleanup afterwards without affecting other keys.
The identifier object to create a Redis key for
Private
getCreate a scoped Redis key for Resource locking.
A scoped Redis key that allows cleanup afterwards without affecting other keys.
The identifier object to create a Redis key for
Releases a lock on the requested identifier. The promise will resolve when the lock has been released. In case there is no lock on the resource an error should be thrown.
Resource to release the lock on.
Private
tryTry a Redis function according to the set AttemptSettings Since the locking strategy is custom-built on Redis and Redis itself does not have a lock concept, this function allows us to wait until we acquired a lock.
The AttemptSettings will dictate how many times we should retry the Redis functions before giving up and throwing an error.
Promise that resolves if operation succeeded. Rejects with error otherwise
To convert from Redis operation to Promise
The function to try
Run the given function while the resource is locked. The lock will be released when the (async) input function resolves. This function should be used for operations that only require reading the resource.
A promise resolving when the lock is released.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
Run the given function while the resource is locked. The lock will be released when the (async) input function resolves. This function should be used for operations that could modify the resource.
A promise resolving when the lock is released.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
A Redis Locker that can be used as both:
The Read Write algorithm roughly goes as follows:
The Resource locking algorithm uses a single mutex/lock.
All operations, such as checking for a write lock AND read count, are executed in a single Lua script. These scripts are used by Redis as a single new command. Redis executes its operations in a single thread, as such, each such operation can be considered atomic.
See