Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RedisCache

Distributed cache that stores values in 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:
    • retries: number of retries (default: 3)
    • timeout: default caching timeout in milliseconds (default: 1 minute)
    • max_size: maximum number of values stored in this cache (default: 1000)

References

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

Example

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

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

cache.store("123", "key1", "ABC", (err) => {
     cache.store("123", "key1", (err, value) => {
         // Result: "ABC"
     });
});

Hierarchy

  • RedisCache

Implements

  • any
  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of this cache.

    Returns RedisCache

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

remove

  • remove(correlationId: string, key: string, callback: function): void
  • Removes a value from the cache by its key.

    Parameters

    • correlationId: string

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

    • key: string

      a unique value key.

    • callback: function

      (optional) callback function that receives an error or null for success

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

retrieve

  • retrieve(correlationId: string, key: string, callback: function): void
  • Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns null.

    Parameters

    • correlationId: string

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

    • key: string

      a unique value key.

    • callback: function

      callback function that receives cached value or error.

        • (err: any, value: any): void
        • Parameters

          • err: any
          • value: 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

store

  • store(correlationId: string, key: string, value: any, timeout: number, callback: function): void
  • Stores value in the cache with expiration time.

    Parameters

    • correlationId: string

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

    • key: string

      a unique value key.

    • value: any

      a value to store.

    • timeout: number

      expiration timeout in milliseconds.

    • callback: function

      (optional) callback function that receives an error or null for success

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Generated using TypeDoc