KV
A key-value store bound to env.NAME.
Configuration
"kv_namespaces": ["SESSIONS"]
Bare names are auto-provisioned on deploy; see Storage resources.
Usage
env.SESSIONS.put("k", "v");
env.SESSIONS.put("session:abc", token, { expirationTtl: 3600 });
env.SESSIONS.get("k"); // -> "v" or null
env.SESSIONS.delete("k");
env.SESSIONS.list("session:"); // -> string[] of keys
From compatibility date 2026-10-25 KV calls return Promises, as on Workers; before it they are synchronous. await works at both.
Methods
| Method | Signature | Returns |
|---|---|---|
put |
(key, value, { expirationTtl?, expiration? }) |
void. The value is converted to a string. |
get |
(key) |
string | null |
delete |
(key) |
void |
list |
(prefix?) |
string[] of keys, sorted. Up to 1000 on the platform. |
expirationTtl is seconds from now, at least 60. expiration is an absolute time in Unix seconds. An expired key reads as null and is left out of list.
Related
- Storage resources and auto-provisioning
- Manage and export KV data: list, read, edit and export keys from the CLI