Options
All
  • Public
  • Public/Protected
  • All
Menu

A storage provider that uses IORedis. This implemenation uses Redis pub/sub as a method to retrieve updates from other nodes whenever keys change.

Type parameters

  • TKey

  • TValue

Hierarchy

  • RedisPubSubProvider

Implements

  • ISubscribableStorageProvider<TKey, TValue>

Index

Constructors

constructor

  • Type parameters

    • TKey

    • TValue

    Parameters

    • client: Redis | Cluster

      The IORedis client for general read/write that has been initialized

    • channel: Redis | Cluster

      The IORedis client for listening to updates from other nodes that has been

    • config: IRedisProviderOptions<TKey, TValue>

      The set of options for the behavior of this storage provider initialized, undefined if subscribe/unsubscribe isn't needed.

    Returns RedisPubSubProvider<TKey, TValue>

Properties

Private Readonly config

config: Required<IRedisProviderOptions<TKey, TValue>>

Private isListening

isListening: boolean = false

Readonly isPersistable

isPersistable: boolean

Private Readonly logger

logger: Logger = ...

Private Readonly updateHandlers

updateHandlers: StorageProviderUpdateHandler<TKey, TValue>[] = []

Methods

delete

  • delete(key: TKey): Promise<boolean | IAgedValue<TValue>>
  • Parameters

    • key: TKey

      The key to the value to delete

    Returns Promise<boolean | IAgedValue<TValue>>

    The value deleted or boolean (value | true is success). A provider is not required to return a value

get

  • get(key: TKey): Promise<null | IAgedValue<TValue>>
  • Parameters

    • key: TKey

      The key to retrieve

    Returns Promise<null | IAgedValue<TValue>>

    The value if retreiving was successful or null

Private handleChannelMessage

  • handleChannelMessage(channel: string, message: string): void

keys

  • keys(): Promise<TKey[]>

listen

  • listen(): Promise<boolean>
  • This should be called if subscribe/unsubscribe functionality is needed. channel must be set in the constructor.

    Returns Promise<boolean>

    If subscribing the Redis channel was successful.

set

  • set(key: TKey, agedValue: IAgedValue<TValue>): Promise<null | IAgedValue<TValue>>
  • Parameters

    • key: TKey

      The key to set

    • agedValue: IAgedValue<TValue>

    Returns Promise<null | IAgedValue<TValue>>

    The value written if successful or null

size

  • size(): Promise<number>

subscribe

  • subscribe(handler: StorageProviderUpdateHandler<TKey, TValue>): boolean
  • Whenever a key/value changes, the storage provider can notify observers, so that they can react accordingly. This will add the observer until an unsubscribe() is called

    Parameters

    • handler: StorageProviderUpdateHandler<TKey, TValue>

      The function that will execute when a key/value changes

    Returns boolean

    If subscribing to changes was successful

unsubscribe

  • unsubscribe(handler: StorageProviderUpdateHandler<TKey, TValue>): boolean
  • Parameters

    • handler: StorageProviderUpdateHandler<TKey, TValue>

      The function to remove

    Returns boolean

    If unsubscribing to changes was successful

Generated using TypeDoc