Architecture
State is server-side key-value storage with trigger-based reactivity. Unlike streams, state does not push updates to WebSocket clients — it fires triggers that workers handle server-side.Sample Configuration
Configuration
The adapter to use for state persistence and distribution. Defaults to
modules::state::adapters::KvStore when not specified.Adapters
modules::state::adapters::KvStore
Built-in key-value store. Supports both in-memory and file-based persistence.Configuration
Storage method. Options:
in_memory (lost on restart) or file_based (persisted to disk).Directory path for file-based storage. Each scope is stored as a separate file.
Interval in milliseconds between automatic disk saves. Defaults to
5000.modules::state::adapters::RedisAdapter
Uses Redis as the state backend.Configuration
The URL of the Redis instance to use.
modules::state::adapters::Bridge
Forwards state operations to a remote III Engine instance via the Bridge Client.Functions
Set a value in state. Fires a
state:created trigger if the key did not exist, or state:updated if it did.Parameters
Parameters
Atomically update a value using one or more operations. Fires
state:created or state:updated depending on whether the key existed.Parameters
Parameters
List all values within a scope.
Parameters
Parameters
The scope to list entries from.
Returns
Returns
A flat JSON array of all stored values within the scope:
any[].List all scopes that contain state data.
Returns
Returns
An object with a single
groups field:A sorted, deduplicated array of all scope names that contain at least one key.
Trigger Type
This module adds a new Trigger Type:state.
When a state value is created, updated, or deleted, all registered state triggers are evaluated and fired if they match.
State Event Payload
When the trigger fires, the handler receives a state event object:Always
"state".The kind of change:
"state:created", "state:updated", or "state:deleted".The scope where the change occurred.
The key that changed.
The previous value before the change, or
null for newly created keys.The new value after the change.
null for deleted keys.Sample Code
- Node / TypeScript
- Python
- Rust
Usage Example: User Profile with Reactive Sync
Store user profiles in state and react when they change:- Node / TypeScript
- Python
- Rust
Usage Example: Conditional Trigger
Only process profile updates when the email field changed:- Node / TypeScript
- Python
- Rust