Skip to main content

Module kv

Module kv 

Source
Expand description

Key-value storage for plugin state.

Provides persistent storage that survives across plugin invocations.

§Example

use zlayer_sdk::kv;

// Store a value
kv::set("state", "counter", b"42")?;

// Retrieve a value
if let Some(data) = kv::get("state", "counter")? {
    let count: i32 = core::str::from_utf8(&data)
        .ok()
        .and_then(|s| s.parse().ok())
        .unwrap_or(0);
}

// String convenience methods
kv::set_string("state", "name", "my-value")?;
let name = kv::get_string("state", "name")?;

Functions§

compare_and_swap
Compare and swap - set value only if current value matches expected.
delete
Delete a key.
exists
Check if a key exists.
get
Get a value by key.
get_string
Get a value as a UTF-8 string.
increment
Increment a numeric value atomically.
keys
List all keys with a given prefix within a bucket.
set
Set a value.
set_string
Set a string value.
set_with_ttl
Set a value with a TTL (time-to-live) in seconds.