Skip to main content

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
Example:

Stream Keys

Stream keys follow the format: stream_name::group_id::item_id
  • stream_name: The stream namespace
  • group_id: Group identifier (e.g., user ID, session ID)
  • item_id: Item identifier within the group
Examples:
  • orders::user-123::order-456
  • counters::daily::page-views
  • sessions::session-abc::state

Atomic Operations

update

Perform atomic updates with multiple operations.
impl Into<String>
required
Stream key in the format stream::group::item
Vec<UpdateOp>
required
List of operations to apply atomically
Result<UpdateResult, IIIError>
Result containing old and new values
Example:
All operations in an update call are applied atomically. Either all succeed or none are applied.

Convenience Methods

increment

Atomically increment a numeric field.
Example:

decrement

Atomically decrement a numeric field.
Example:

set_field

Atomically set a field value.
Example:

remove_field

Atomically remove a field.
Example:

merge

Atomically merge an object into the existing value.
Example:

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.
Example:

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