Skip to main content

keys

Creates, updates, deletes, gets or lists a keys resource.

Overview

Namekeys
TypeResource
Idcloudflare.kv.keys

Fields

The following fields are returned by SELECT queries:

List a Namespace's Keys response.

NameDatatypeDescription
namestringA 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)
expirationnumberThe 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.
metadataArbitrary JSON that is associated with a key.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectnamespace_id, account_idlimit, prefix, cursorLists a namespace's keys.
bulk_updatereplacenamespace_id, account_idWrite 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.
bulkexecnamespace_id, account_idRemove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
create_deleteexecnamespace_id, account_idRemove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
getexecnamespace_id, account_id, keysRetrieve 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.

NameDatatypeDescription
account_idstringThe Cloudflare account ID.
namespace_idstringThe Workers KV namespace ID.
cursorstring
limitnumber
prefixstring

SELECT examples

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

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

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
;