worker-kv

Crates.ioworker-kv
lib.rsworker-kv
version0.8.0
sourcesrc
created_at2021-03-21 18:13:59.938134
updated_at2024-09-25 14:48:15.351834
descriptionRust bindings to Cloudflare Worker KV Stores.
homepage
repositoryhttps://github.com/cloudflare/workers-rs
max_upload_size
id371797
size22,665
Zeb Piasecki (zebp)

documentation

README

worker-kv

Docs.rs Crates.io MIT Apache 2

Rust bindings to Cloudflare Worker KV Stores using wasm-bindgen and js-sys.

Example

let kv = KvStore::create("Example")?; // or KvStore::from_this(&this, "Example") if using modules format Workers

// Insert a new entry into the kv.
kv.put("example_key", "example_value")?
    .metadata(vec![1, 2, 3, 4]) // Use some arbitrary serialiazable metadata
    .execute()
    .await?;

// NOTE: kv changes can take a minute to become visible to other workers.
// Get that same metadata.
let (value, metadata) = kv.get("example_key").text_with_metadata::<Vec<usize>>().await?;

For a more complete example check out the full example.

How do I use futures in WebAssembly?

There currently is not a way to use a Future natively from WebAssembly but with the future_to_promise function from wasm_bindgen_futures we can convert it to a standard JavaScript promise, which can be awaited in the regular JavaScript context.

Commit count: 734

cargo fmt