Cloudflare Worker KV: get() with an array of keys returns empty, but Promise.all works.

Hello everyone, I'm encountering an issue with the Cloudflare Worker KV where I get an empty array when trying to retrieve multiple keys at once. When I run the following code, it returns an empty array:
const values = await options.env.TEST.get(["2930", "2929"]);
console.log([...values.entries()]); // []

// Expected: [["2930", "foo"],["2929","bar"]]
const values = await options.env.TEST.get(["2930", "2929"]);
console.log([...values.entries()]); // []

// Expected: [["2930", "foo"],["2929","bar"]]
However, this alternative approach works as expected:
const values = await Promise.all(["2930", "2929"].map((key) => options.env.TEST.get(key)));
console.log(values); // ["foo", "bar"]
const values = await Promise.all(["2930", "2929"].map((key) => options.env.TEST.get(key)));
console.log(values); // ["foo", "bar"]
According to the documentation, passing an array of keys to the get() method should return a Map of the key-value pairs. Here is my wrangler.jsonc file for reference:
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "***",
"main": "./src/index.ts",
"compatibility_date": "2025-06-20",
"observability": {
"enabled": true
},
"assets": {
"directory": "./public/",
"binding": "ASSETS"
},
"kv_namespaces": [
{
"binding": "TEST",
"id": "***",
"preview_id": "***"
}
]
}
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "***",
"main": "./src/index.ts",
"compatibility_date": "2025-06-20",
"observability": {
"enabled": true
},
"assets": {
"directory": "./public/",
"binding": "ASSETS"
},
"kv_namespaces": [
{
"binding": "TEST",
"id": "***",
"preview_id": "***"
}
]
}
I've also made sure that the preview_id is correctly configured for use with wrangler dev. Has anyone else experienced this issue or has any idea what might be going wrong? Thanks
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?