When calling get using a key obtained from the list, null may be returned even if the key exists. Is
When calling get using a key obtained from the list, null may be returned even if the key exists. Is this behavior caused by KV consistency?
const keys = await env.NAMESPACE.list();
Promise.all(keys.map(async (key) => {
const v = env.NAMESPACE.get(key.name);
console.log(v);
}))
just getting the value and incrementing it would be too inefficient since it would be two requests to the KV every time the button is clicked.Not only that, KV is eventually consistent. If you do a
get() in one datacenter and then increment and a put(), another datacenter might not see it for up to 60 seconds so that datacenter might also do a get() and a put() (using the stale value) and then your counter is no longer consistent since a write would be lost.
cloudflare typescript SDK, which resolves the metadata bug reported above with workers kv updates and reads. You are now able to write, update & read the metadata from the typescript SDK! Go try it out npm i cloudflare. There are 124 other projects in the npm registry using cloudflare.
list() call (which is billed) or a get()/getWithMetadata() call (which is also billed). So yes.waitUntil() to avoid delaying the request.




get()get()get()put()put()cloudflarenpm i cloudflarelist()getWithMetadata()waitUntil()const state = ulid(Date.now());
const stateData: StateData = {
returnTo: safeReturn,
codeVerifier: verifier,
createdAt: Date.now(),
expiresAt: Date.now() + this.STATE_TTL_MS
};
await this.stateDatabase.set(state, JSON.stringify(stateData), {
expirationTtl: this.STATE_TTL_MS
});