State
State Management between servers using appolo-state and redis
#
Installation#
Optionskey | Description | Type | Default |
---|---|---|---|
id | stateProvider injection id | string | stateProvider |
maxStates | max state history | number | 1 |
cache | save state cache on the server | boolean | true |
cacheTime | max cache time for valid state | number | 60 * 1000 |
redis | redis connection string | string | `` |
in config/modules/all.ts
#
UsageState class must inherit from Store
.
The store instance will be singleton.
now we can inject store and change the state. The state will be changed on all servers connected to the store by name.
#
Api#
getState#
getState(): Promisereturn the current state
#
statesCount #
get statesCount(): Promisereturn total number of states
#
states#
states(): AsyncIterableIteratorreturn states iterator
#
stateAt#
stateAt(index: number): Promise<T>return state at index
#
setState#
setState(value: Partial<T> | T, options?: SetStateOptions)set new state
#
increment#
increment(path: string, inc: number): Promise<void>increment counter by path
#
lock#
lock(timeMilli = 5000, retryMilli = 5): Promise<T>get state and lock for given time is state is locked it will retry with retryMilli.
#
prevState#
get prevState(): Promise<T>return the previous state
#
goToPrevState#
get goToPrevState(): Promise<T>set the previous state as the current state
#
nextState#
get nextState(): Promise<T>return the next state
#
goToNextState#
get goToNextState(): Promise<T>set the next state as the current state
#
goToState#
get goToState(index: number): Promise<T>set current state by previous state index
#
reset#
reset(state?: T)reset the state to init state or given state
#
quit#
quit()disconnect form redis and stop listen to events