Hello, there. As stated in my title, is there a way to get the total amount of keys for a given list call?
If not, it would be greatly beneficial for me for counting how many items are stored in total for a given prefix.
For example:
const listedData = await KV.list({ prefix: "user:123" })
console.log(listedData.totalKeys) // --> X
This would allow me to understand how much data is associated with a user.
Not possible yet, the only way currently is to get each list until there’s no cursor returned and then check the array size. Keep in mind that listing keys is much more expensive than reading keys.
Alternatively you can use the API to list keys:
https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
And it will return a “count” but only for the current cursor.
Plus, when you’re listing via the API you have a rate-limit you must stay within (1,200 requests in a five minute period)