Skip to content

Cloudflare.KV reference

Source: src/Cloudflare/KV/Namespace.ts

A Cloudflare Workers KV namespace for key-value storage at the edge.

KV provides eventually-consistent, low-latency reads with global replication. Create a namespace as a resource, then bind it to a Worker to get/put values at runtime.

const kv = yield* Cloudflare.KV.Namespace("MyKV");
const kv = yield* Cloudflare.KV.ReadWriteNamespace(MyKV);
// Read a value
const value = yield* kv.get("my-key");
// Write a value
yield* kv.put("my-key", "hello world");

Provide Cloudflare.KV.ReadWriteNamespaceBinding (native Worker binding) or Cloudflare.KV.ReadWriteNamespaceHttp (scoped HTTP token) in the worker’s runtime layer. Use Cloudflare.KV.ReadNamespace / Cloudflare.KV.WriteNamespace for least-privilege read- or write-only access.

Source: src/Cloudflare/KV/ReadNamespace.ts

Bind a Namespace to a Worker with read access and obtain the Effect-native KV client (get, getWithMetadata, list).

ReadNamespace is a single identifier that is simultaneously the binding’s Context tag, its type, and the callable — yield* Cloudflare.KV.ReadNamespace(ns).

Source: src/Cloudflare/KV/ReadWriteNamespace.ts

Bind a Namespace to a Worker with read + write access and obtain the Effect-native KV client (get, getWithMetadata, list, put, delete).

ReadWriteNamespace is a single identifier that is simultaneously the binding’s Context tag, its type, and the callable — yield* Cloudflare.KV.ReadWriteNamespace(ns).

Source: src/Cloudflare/KV/WriteNamespace.ts

Bind a Namespace to a Worker with write access and obtain the Effect-native KV client (put, delete).

WriteNamespace is a single identifier that is simultaneously the binding’s Context tag, its type, and the callable — yield* Cloudflare.KV.WriteNamespace(ns).