Acquires a lock on the requested identifier. The promise will resolve when the lock has been acquired.
Generate and return a RedisClient based on the provided string
A string that contains either a host address and a port number like '127.0.0.1:6379' or just a port number like '6379'.
Create a scoped Redis key for Read-Write locking.
The identifier object to create a Redis key for
A scoped Redis key that allows cleanup afterwards without affecting other keys.
Create a scoped Redis key for Resource locking.
The identifier object to create a Redis key for
A scoped Redis key that allows cleanup afterwards without affecting other keys.
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.
Try 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.
The function to try
Promise that resolves if operation succeeded. Rejects with error otherwise
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.
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.
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.