Overview
The Streams API provides atomic operations on stream data. Streams are key-value stores that support atomic updates with multiple operations (increment, set, merge, etc.).Creating a Streams Instance
Streams::new
Create a new Streams instance for performing atomic updates.III
required
III client instance
Stream Keys
Stream keys follow the format:stream_name::group_id::item_id
stream_name: The stream namespacegroup_id: Group identifier (e.g., user ID, session ID)item_id: Item identifier within the group
orders::user-123::order-456counters::daily::page-viewssessions::session-abc::state
Atomic Operations
update
Perform atomic updates with multiple operations.impl Into<String>
required
Stream key in the format
stream::group::itemVec<UpdateOp>
required
List of operations to apply atomically
Result<UpdateResult, IIIError>
Result containing old and new values
All operations in an
update call are applied atomically. Either all succeed or none are applied.Convenience Methods
increment
Atomically increment a numeric field.decrement
Atomically decrement a numeric field.set_field
Atomically set a field value.remove_field
Atomically remove a field.merge
Atomically merge an object into the existing value.Update Operations
UpdateOp
Operations that can be performed atomically.Creating UpdateOps
UpdateBuilder
Build complex update operations fluently.Result Types
UpdateResult
Result of an atomic update operation.Field Paths
Field paths use dot notation to access nested fields:Complete Example
Here’s a complete example showing stream operations:Use Cases
Counters and Analytics
User Sessions
Inventory Management
See Also
- Channels API - Stream binary data between workers
- Functions API - Process stream updates in functions
- Triggers API - React to stream changes with triggers