Workers KV namespaces
A Workers KV namespace is a key-value database replicated to Cloudflare’s global network.
Bind your Workers KV namespaces through Wrangler or via the Cloudflare dashboard.
To bind Workers KV namespaces to your Worker, assign an array of the below object to the kv_namespaces key.
-
bindingstring required- The binding name used to refer to the Workers KV namespace.
-
idstring required- The ID of the Workers KV namespace.
-
preview_idstring optional- The ID of the Workers KV namespace used during
wrangler dev.
- The ID of the Workers KV namespace used during
Example:
kv_namespaces = [ { binding = "<TEST_NAMESPACE>", id = "<TEST_ID>" }]To bind the namespace to your Worker in the Cloudflare dashboard:
- Log in to the Cloudflare dashboard ↗.
- Go to Workers & Pages.
- Select your Worker.
- Select Settings > Bindings.
- Select Add.
- Select KV Namespace.
- Enter your desired variable name (the name of the binding).
- Select the KV namespace you wish to bind the Worker to.
- Select Deploy.