Skip to content

PURISTA API / Modules / @purista/redis-state-store / RedisStateStore

Class: RedisStateStore<M, F, S>

@purista/redis-state-store.RedisStateStore

A state store for using redis as storage. State values are stored as stringified JSON.

Per default, setting/changing and removal of values are enabled.

Example

typescript
const config = {
 enableGet: true, // optional, default is true
 enableRemove: true, // optional, default is true
 enableSet: true, // optional, default is true
 url: 'redis://alice:foobared@awesome.redis.server:6379'
}

const store = new RedisStateStore({ config })

await store.setState('stateKey',{ myState: 'value' })

let value = await store.getState('stateKey')
console.log(value) // outputs: { stateKey: { myState: 'value' } }

await store.removeState('stateKey')

value = await store.getState('stateKey')
console.log(value) // outputs: undefined

See documentation of underlaying redis lib package for detailed configuration options.

See

NODE-REDIS

Type parameters

NameType
Mextends RedisModules = RedisModules
Fextends RedisFunctions = RedisFunctions
Sextends RedisScripts = RedisScripts

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new RedisStateStore<M, F, S>(config?): RedisStateStore<M, F, S>

Type parameters

NameType
Mextends RedisModules = RedisModules
Fextends RedisFunctions = RedisFunctions
Sextends RedisScripts = RedisScripts

Parameters

NameTypeDescription
config?Object-
config.cacheTtl?numberCache time to live in ms
config.config?RedisClientOptions<M, F, S>-
config.enableCache?booleanEnable cache
config.enableGet?booleanEnable generally get method
config.enableRemove?booleanEnable generally remove method
config.enableSet?booleanEnable generally set method
config.logLevel?LogLevelNameA log level for new logger if logger is not set
config.logger?LoggerA logger instance

Returns

RedisStateStore<M, F, S>

Overrides

StateStoreBaseClass.constructor

Defined in

redis-state-store/src/RedisStateStore.impl.ts:48

Properties

client

client: RedisClientType<M, F, S>

Defined in

redis-state-store/src/RedisStateStore.impl.ts:46


config

config: Object

Type declaration

NameTypeDescription
cacheTtl?numberCache time to live in ms
config?RedisClientOptions<M, F, S>-
enableCache?booleanEnable cache
enableGet?booleanEnable generally get method
enableRemove?booleanEnable generally remove method
enableSet?booleanEnable generally set method
logLevel?LogLevelNameA log level for new logger if logger is not set
logger?LoggerA logger instance

Inherited from

StateStoreBaseClass.config

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:16


logger

logger: Logger

Inherited from

StateStoreBaseClass.logger

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:15


name

name: string

Inherited from

StateStoreBaseClass.name

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:17

Methods

destroy

destroy(): Promise<void>

Returns

Promise<void>

Overrides

StateStoreBaseClass.destroy

Defined in

redis-state-store/src/RedisStateStore.impl.ts:107


getClient

getClient(): Promise<RedisClientType<M, F, S>>

Returns

Promise<RedisClientType<M, F, S>>

Defined in

redis-state-store/src/RedisStateStore.impl.ts:54


getState

getState<StateNames>(...stateNames): Promise<ObjectWithKeysFromStringArray<StateNames>>

Type parameters

NameType
StateNamesextends string[]

Parameters

NameType
...stateNamesStateNames

Returns

Promise<ObjectWithKeysFromStringArray<StateNames>>

Inherited from

StateStoreBaseClass.getState

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:20


getStateImpl

getStateImpl<StateNames>(...stateNames): Promise<ObjectWithKeysFromStringArray<StateNames>>

Type parameters

NameType
StateNamesextends string[]

Parameters

NameType
...stateNamesStateNames

Returns

Promise<ObjectWithKeysFromStringArray<StateNames>>

Overrides

StateStoreBaseClass.getStateImpl

Defined in

redis-state-store/src/RedisStateStore.impl.ts:61


removeState

removeState(stateName): Promise<void>

Parameters

NameType
stateNamestring

Returns

Promise<void>

Inherited from

StateStoreBaseClass.removeState

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:22


removeStateImpl

removeStateImpl(stateName): Promise<void>

Parameters

NameType
stateNamestring

Returns

Promise<void>

Overrides

StateStoreBaseClass.removeStateImpl

Defined in

redis-state-store/src/RedisStateStore.impl.ts:80


setState

setState(stateName, stateValue): Promise<void>

Parameters

NameType
stateNamestring
stateValueunknown

Returns

Promise<void>

Inherited from

StateStoreBaseClass.setState

Defined in

core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:24


setStateImpl

setStateImpl(stateName, stateValue): Promise<void>

Parameters

NameType
stateNamestring
stateValueunknown

Returns

Promise<void>

Overrides

StateStoreBaseClass.setStateImpl

Defined in

redis-state-store/src/RedisStateStore.impl.ts:92