Creates a new RedisClient
Redis connection string of a standalone Redis node
Override default AttemptSettings
Addition settings used to create the Redis client or to interact with the Redis server
Private
Readonly
attemptPrivate
finalizedProtected
Readonly
loggerPrivate
Readonly
namespacePrivate
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
clearPrivate
createGenerate 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'.
Private
getCreate 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.
Private
getCreate 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.
Resource to release the lock on.
Private
swallowWrapper function for all (un)lock operations. If the fn()
resolves to false (after applying
fromResp2ToBool, the result will be swallowed. When fn()
resolves to true, this wrapper
will return true. Any error coming from fn()
will be thrown.
The function reference to swallow false from.
Wrapper function for all (un)lock operations. If the fn()
resolves to false (after applying
fromResp2ToBool, the result will be swallowed. When fn()
resolves to true, this wrapper
will return true. Any error coming from fn()
will be thrown.
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