Store defines a concurrent safe in memory key-value data store.

Type Parameters

  • T

Hierarchy

  • Store

Methods

  • Get returns a single element value from the store.

    If key is not set, the zero T value is returned.

    Parameters

    • key: string

    Returns T

  • GetOk is similar to Get but returns also a boolean indicating whether the key exists or not.

    Parameters

    • key: string

    Returns [T, boolean]

  • GetOrSet retrieves a single existing value for the provided key or stores a new one if it doesn't exist.

    Parameters

    • key: string
    • setFunc: (() => T)
        • (): T
        • Returns T

    Returns T

  • Has checks if element with the specified key exist or not.

    Parameters

    • key: string

    Returns boolean

  • Length returns the current number of elements in the store.

    Returns number

  • MarshalJSON implements [json.Marshaler] and export the current store data into valid JSON.

    Returns string | number[]

  • Remove removes a single entry from the store.

    Remove does nothing if key doesn't exist in the store.

    Parameters

    • key: string

    Returns void

  • RemoveAll removes all the existing store entries.

    Returns void

  • Reset clears the store and replaces the store data with a shallow copy of the provided newData.

    Parameters

    Returns void

  • Set sets (or overwrite if already exist) a new value for key.

    Parameters

    • key: string
    • value: T

    Returns void

  • SetIfLessThanLimit sets (or overwrite if already exist) a new value for key.

    This method is similar to Set() but it will skip adding new elements to the store if the store length has reached the specified limit. false is returned if maxAllowedElements limit is reached.

    Parameters

    • key: string
    • value: T
    • maxAllowedElements: number

    Returns boolean

  • UnmarshalJSON implements [json.Unmarshaler] and imports the provided JSON data into the store.

    The store entries that match with the ones from the data will be overwritten with the new value.

    Parameters

    • data: string | number[]

    Returns void

  • Values returns a slice with all of the current store values.

    Returns T[]

Generated using TypeDoc