Options
All
  • Public
  • Public/Protected
  • All
Menu

A locking system that uses a Redis server or any number of Redis nodes / clusters This solution has issues though:

  • Redlock wants to handle expiration itself, this is against the design of a ResourceLocker. The workaround for this is to extend an active lock indefinitely.
  • This solution is not multithreaded! If threadA locks a resource, only threadA can unlock this resource. If threadB wont be able to lock a resource if threadA already acquired that lock, in that sense it is kind of multithreaded.
  • Redlock does not provide the ability to see which locks have expired

Hierarchy

  • RedisResourceLocker

Implements

Index

Constructors

constructor

  • new RedisResourceLocker(redisClients: string[], redlockOptions?: Record<string, number>): RedisResourceLocker

Properties

Private Readonly lockMap

lockMap: Map<string, { interval: Timeout; lock: Lock }>

Protected Readonly logger

logger: Logger = ...

Private Readonly redlock

redlock: Redlock

Methods

acquire

Private createRedisClients

  • createRedisClients(redisClientsStrings: string[]): RedisClient[]
  • Generate and return a list of RedisClients based on the provided strings

    Parameters

    • redisClientsStrings: string[]

      a list of strings that contain either a host address and a port number like '127.0.0.1:6379' or just a port number like '6379'

    Returns RedisClient[]

Private createRedlock

  • createRedlock(clients: RedisClient[], redlockOptions?: Record<string, number>): Redlock
  • Generate and return a Redlock instance

    Parameters

    • clients: RedisClient[]

      a list of RedisClients you want to use for the redlock instance

    • redlockOptions: Record<string, number> = {}

      extra redlock options to overwrite the default config

    Returns Redlock

Private extendLockIndefinitely

  • extendLockIndefinitely(identifier: string): Timeout
  • This function is internally used to keep an acquired lock active, a wrapper class will handle expiration

    Parameters

    • identifier: string

      Identifier of the lock to be extended

    Returns Timeout

finalize

  • finalize(): Promise<void>

Private getLockCount

  • getLockCount(): number

release

  • 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.

    Parameters

    Returns Promise<void>