Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RedisLock

Distributed lock that is implemented based on Redis in-memory database.

Configuration parameters

  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it
  • credential(s):
    • store_key: key to retrieve parameters from credential store
    • username: user name (currently is not used)
    • password: user password
  • options:
    • retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
    • retries: number of retries (default: 3)

References

  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credential

Example

let lock = new RedisRedis();
lock.configure(ConfigParams.fromTuples(
  "host", "localhost",
  "port", 6379
));

lock.open("123", (err) => {
  ...
});

lock.acquire("123", "key1", (err) => {
     if (err == null) {
         try {
           // Processing...
         } finally {
            lock.releaseLock("123", "key1", (err) => {
                // Continue...
            });
         }
     }
});

Hierarchy

Implements

  • any
  • any
  • any

Index

Methods

close

  • close(correlationId: string, callback: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback: function): void
  • Opens the component.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

releaseLock

  • releaseLock(correlationId: string, key: string, callback?: function): void
  • Releases prevously acquired lock by its key.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique lock key to release.

    • Optional callback: function

      callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

tryAcquireLock

  • tryAcquireLock(correlationId: string, key: string, ttl: number, callback: function): void
  • Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique lock key to acquire.

    • ttl: number

      a lock timeout (time to live) in milliseconds.

    • callback: function

      callback function that receives a lock result or error.

        • (err: any, result: boolean): void
        • Parameters

          • err: any
          • result: boolean

          Returns void

    Returns void

Generated using TypeDoc