Hi - Is there a difference in the below
Hi - Is there a difference in the below two calls? I'm getting two different results for
const value = await env.NAMESPACE.list({ prefix: "testing" });
vs
a call to
https://api.cloudflare.com/client/v4
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys/prefix=testing
It seems that the default should be 1000 if not provided. My storage has around 200-300 items with the prefix but the first one would return an arbitrary number at times(e.g. 50, 93) while the rest call would always return all of them. I wonder if the first case could be suffering from It is possible to have an empty array in keys, but still have more keys to fetch, because recently expired or deleted keys ↗ must be iterated through but will not be included in the returned keys.
where the deleted ones are counted as part of the limit but the second one is not?3 Replies
Hi Swee! Can you share your KV namespace ID?
Checked in with the team - When you use the REST API, we'll go and paginate through your KV pairs on your behalf calling (up to a certain point), whereas with the binding, we provide the cursor for you to do the list and page navigations yourself
Hey @thomasgauvin ! Thanks for the response. Can you clarify the auto pagination bit for the rest api? If the default limit is 1000 keys per request (for either API and Binding), and i have less than that in the storage, wouldn’t one call retrieve all the keys? By auto paginate do you mean it would skip the recently expired/deleted keys and not include it as part of the limit count?
The API does the pagination on your behalf, skipping deleted items. The binding does not, and requires you to paginate yourself, since the limit also includes recently deleted keys for the binding