Creates a new RedisClient
Redis connection string of a standalone Redis node
Override default AttemptSettings
Optional
redisSettings: RedisSettingsAddition settings used to create the Redis client or to interact with the Redis server
Acquires a lock on the requested identifier. The promise will resolve when the lock has been acquired.
Resource to acquire a lock on.
Releases a lock on the requested identifier. The promise will resolve when the lock has been released. If there is no lock on the resource, an error should be thrown.
Resource to release the lock on.
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.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
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.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
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.
The operation to (un)lock will always resolve with either 1/OK/true if succeeded or 0/false if not succeeded. Rejection with errors will be happen on actual failures. Retrying the (un)lock operations will be done by making use of the LockUtils' retryFunctionUntil function.
See