Wrangler KV commands
Manage Workers KV namespaces.
Create a new namespace.
NAMESPACE
string required- The name of the new namespace.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace (the
preview_id
value).
- Interact with a preview namespace (the
The following is an example of using the create
command to create a KV namespace called MY_KV
.
The following is an example of using the create
command to create a preview KV namespace called MY_KV
.
List all KV namespaces associated with the current account ID.
The following is an example that passes the Wrangler command through the jq
command:
Delete a given namespace.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to delete.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to delete.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
The following is an example of deleting a KV namespace called MY_KV.
The following is an example of deleting a preview KV namespace called MY_KV
.
Manage key-value pairs within a Workers KV namespace.
Write a single key-value pair to a particular namespace.
KEY
string required- The key to write to.
VALUE
string optional- The value to write.
--path
optional- When defined, the value is loaded from the file at
--path
rather than reading it from theVALUE
argument. This is ideal for security-sensitive operations because it avoids saving keys and values into your terminal history.
- When defined, the value is loaded from the file at
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to write to.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to write to.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--ttl
number optional- The lifetime (in number of seconds) that the key-value pair should exist before expiring. Must be at least
60
seconds. This option takes precedence over theexpiration
option.
- The lifetime (in number of seconds) that the key-value pair should exist before expiring. Must be at least
--expiration
number optional- The timestamp, in UNIX seconds, indicating when the key-value pair should expire.
--metadata
string optional- Any (escaped) JSON serialized arbitrary object to a maximum of 1024 bytes.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
The following is an example that puts a key-value into the namespace with binding name of MY_KV
.
The following is an example that puts a key-value into the preview namespace with binding name of MY_KV
.
The following is an example that puts a key-value into a namespace, with a time-to-live value of 10000
seconds.
The following is an example that puts a key-value into a namespace, where the value is read from the value.txt
file.
Output a list of all keys in a given namespace.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to list from.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to list from.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--prefix
string optional- Only list keys that begin with the given prefix.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
Below is an example that passes the Wrangler command through the jq
command:
Read a single value by key from the given namespace.
KEY
string required- The key value to get.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to get from.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to get from.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--text
boolean optional- Decode the returned value as a UTF-8 string.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
The following is an example that gets the value of the "my-key"
key from the KV namespace with binding name MY_KV
.
Remove a single key value pair from the given namespace.
KEY
string required- The key value to get.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to delete from.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to delete from.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
The following is an example that deletes the key-value pair with key "my-key"
from the KV namespace with binding name MY_KV
.
Manage multiple key-value pairs within a Workers KV namespace in batches.
Write a JSON file containing an array of key-value pairs to the given namespace.
FILENAME
string required- The JSON file containing an array of key-value pairs to write to the namespace.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to write to.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to write to.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
This command takes a JSON file as an argument with a list of key-value pairs to upload. An example of JSON input:
KV namespace values can only store strings. In order to save complex a value, stringify it to JSON:
Refer to the full schema for key-value entries uploaded via the bulk API:
key
string required- The key’s name. The name may be 512 bytes maximum. All printable, non-whitespace characters are valid.
value
string required- The UTF-8 encoded string to be stored, up to 25 MB in length.
metadata
object optional- Any arbitrary object (must serialize to JSON) to a maximum of 1,024 bytes.
expiration
number optional- The time, measured in number of seconds since the UNIX epoch, at which the key should expire.
expiration_ttl
number optional- The number of seconds the document should exist before expiring. Must be at least
60
seconds.
- The number of seconds the document should exist before expiring. Must be at least
base64
boolean optional- When true, the server will decode the value as base64 before storing it. This is useful for writing values that would otherwise be invalid JSON strings, such as images. Defaults to
false
.
- When true, the server will decode the value as base64 before storing it. This is useful for writing values that would otherwise be invalid JSON strings, such as images. Defaults to
The following is an example of writing all the key-value pairs found in the allthethingsupload.json
file.
Delete all keys read from a JSON file within a given namespace.
FILENAME
string required- The JSON file containing an array of keys to delete from the namespace.
--binding
string- The binding name of the namespace, as stored in the
wrangler.toml
file, to delete from.
- The binding name of the namespace, as stored in the
--namespace-id
string- The ID of the namespace to delete from.
--env
string optional- Perform on a specific environment.
--preview
boolean optional- Interact with a preview namespace instead of production.
--local
boolean optional- Interact with locally persisted data.
--persist-to
string optional- Specify directory for locally persisted data.
This command takes a JSON file as an argument containing an array of keys to delete.
The following is an example of the JSON input:
The following is an example of deleting all the keys found in the allthethingsdelete.json
file.
Below are deprecations to Wrangler commands for Workers KV.
Since version 3.60.0, Wrangler supports the kv ...
syntax. If you are using versions below 3.60.0, the command follows the kv:...
syntax.
The kv:...
syntax is deprecated in versions 3.60.0 and beyond and will be removed in a future major version.
For example, commands using the kv ...
syntax look as such:
The same commands using the kv:...
syntax look as such: