keys
Creates, updates, deletes, gets or lists a keys resource.
Overview
| Name | keys |
| Type | Resource |
| Id | cloudflare.kv.keys |
Fields
The following fields are returned by SELECT queries:
- list
List a Namespace's Keys response.
| Name | Datatype | Description |
|---|---|---|
name | string | A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. (example: My-Key) |
expiration | number | The time, measured in number of seconds since the UNIX epoch, at which the key will expire. This property is omitted for keys that will not expire. |
metadata | | Arbitrary JSON that is associated with a key. |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
list | select | namespace_id, account_id | limit, prefix, cursor | Lists a namespace's keys. |
bulk_update | replace | namespace_id, account_id | Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information. Existing values and expirations will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. The entire request size must be 100 megabytes or less. | |
bulk | exec | namespace_id, account_id | Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed. | |
create_delete | exec | namespace_id, account_id | Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed. | |
get | exec | namespace_id, account_id, keys | Retrieve up to 100 KV pairs from the namespace. Keys must contain text-based values. JSON values can optionally be parsed instead of being returned as a string value. Metadata can be included if withMetadata is true. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
account_id | string | The Cloudflare account ID. |
namespace_id | string | The Workers KV namespace ID. |
cursor | string | |
limit | number | |
prefix | string |
SELECT examples
- list
Lists a namespace's keys.
SELECT
name,
expiration,
metadata
FROM cloudflare.kv.keys
WHERE namespace_id = '{{ namespace_id }}' -- required
AND account_id = '{{ account_id }}' -- required
AND limit = '{{ limit }}'
AND prefix = '{{ prefix }}'
AND cursor = '{{ cursor }}'
;
REPLACE examples
- bulk_update
Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information. Existing values and expirations will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. The entire request size must be 100 megabytes or less.
REPLACE cloudflare.kv.keys
SET
-- No updatable properties
WHERE
namespace_id = '{{ namespace_id }}' --required
AND account_id = '{{ account_id }}' --required
RETURNING
errors,
messages,
result,
success;
Lifecycle Methods
- bulk
- create_delete
- get
Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
EXEC cloudflare.kv.keys.bulk
@namespace_id='{{ namespace_id }}' --required,
@account_id='{{ account_id }}' --required
;
Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
EXEC cloudflare.kv.keys.create_delete
@namespace_id='{{ namespace_id }}' --required,
@account_id='{{ account_id }}' --required
;
Retrieve up to 100 KV pairs from the namespace. Keys must contain text-based values. JSON values can optionally be parsed instead of being returned as a string value. Metadata can be included if withMetadata is true.
EXEC cloudflare.kv.keys.get
@namespace_id='{{ namespace_id }}' --required,
@account_id='{{ account_id }}' --required
@@json=
'{
"keys": "{{ keys }}",
"type": "{{ type }}",
"withMetadata": {{ withMetadata }}
}'
;