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
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
Type parameters
Name | Type |
---|---|
M | extends RedisModules = RedisModules |
F | extends RedisFunctions = RedisFunctions |
S | extends RedisScripts = RedisScripts |
Hierarchy
StateStoreBaseClass
<RedisStoreConfig
<M
,F
,S
>>↳
RedisStateStore
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new RedisStateStore<M
, F
, S
>(config?
): RedisStateStore
<M
, F
, S
>
Type parameters
Name | Type |
---|---|
M | extends RedisModules = RedisModules |
F | extends RedisFunctions = RedisFunctions |
S | extends RedisScripts = RedisScripts |
Parameters
Name | Type | Description |
---|---|---|
config? | Object | - |
config.cacheTtl? | number | Cache time to live in ms |
config.config? | RedisClientOptions <M , F , S > | - |
config.enableCache? | boolean | Enable cache |
config.enableGet? | boolean | Enable generally get method |
config.enableRemove? | boolean | Enable generally remove method |
config.enableSet? | boolean | Enable generally set method |
config.logLevel? | LogLevelName | A log level for new logger if logger is not set |
config.logger? | Logger | A 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
Name | Type | Description |
---|---|---|
cacheTtl? | number | Cache time to live in ms |
config? | RedisClientOptions <M , F , S > | - |
enableCache? | boolean | Enable cache |
enableGet? | boolean | Enable generally get method |
enableRemove? | boolean | Enable generally remove method |
enableSet? | boolean | Enable generally set method |
logLevel? | LogLevelName | A log level for new logger if logger is not set |
logger? | Logger | A logger instance |
Inherited from
Defined in
core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:16
logger
• logger: Logger
Inherited from
Defined in
core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:15
name
• name: string
Inherited from
Defined in
core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:17
Methods
destroy
▸ destroy(): Promise
<void
>
Returns
Promise
<void
>
Overrides
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
Name | Type |
---|---|
StateNames | extends string [] |
Parameters
Name | Type |
---|---|
...stateNames | StateNames |
Returns
Promise
<ObjectWithKeysFromStringArray
<StateNames
>>
Inherited from
Defined in
core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:20
getStateImpl
▸ getStateImpl<StateNames
>(...stateNames
): Promise
<ObjectWithKeysFromStringArray
<StateNames
>>
Type parameters
Name | Type |
---|---|
StateNames | extends string [] |
Parameters
Name | Type |
---|---|
...stateNames | StateNames |
Returns
Promise
<ObjectWithKeysFromStringArray
<StateNames
>>
Overrides
StateStoreBaseClass.getStateImpl
Defined in
redis-state-store/src/RedisStateStore.impl.ts:61
removeState
▸ removeState(stateName
): Promise
<void
>
Parameters
Name | Type |
---|---|
stateName | string |
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
Name | Type |
---|---|
stateName | string |
Returns
Promise
<void
>
Overrides
StateStoreBaseClass.removeStateImpl
Defined in
redis-state-store/src/RedisStateStore.impl.ts:80
setState
▸ setState(stateName
, stateValue
): Promise
<void
>
Parameters
Name | Type |
---|---|
stateName | string |
stateValue | unknown |
Returns
Promise
<void
>
Inherited from
Defined in
core/dist/commonjs/core/StateStore/StateStoreBaseClass.impl.d.ts:24
setStateImpl
▸ setStateImpl(stateName
, stateValue
): Promise
<void
>
Parameters
Name | Type |
---|---|
stateName | string |
stateValue | unknown |
Returns
Promise
<void
>
Overrides
StateStoreBaseClass.setStateImpl