octo3.
octo3.9mo ago

Is there a way to specify a range and list from KV?

const kv = await Deno.openKv();
kv.set(["parent", 1], "key1")
kv.set(["parent", 2], "key1")
kv.set(["parent", 3], "key1")
kv.set(["parent", 4], "key1")
const kv = await Deno.openKv();
kv.set(["parent", 1], "key1")
kv.set(["parent", 2], "key1")
kv.set(["parent", 3], "key1")
kv.set(["parent", 4], "key1")
Is it possible to retrieve only those of these that match the content of ["parent", 1~3] ?
3 Replies
octo3.
octo3.OP9mo ago
The condition of less than or equal to 3 is also acceptable.
cknight
cknight9mo ago
You want the list interface. Here's how it might look:
const entries = await Array.fromAsync(kv.list({start: ["parent", 1], end: ["parent", 3]});
const entries = await Array.fromAsync(kv.list({start: ["parent", 1], end: ["parent", 3]});
There's also the getMany interface to get multiple keys at once. https://deno.land/api@v1.41.3?s=Deno.Kv&unstable=&p=prototype.getMany
octo3.
octo3.OP9mo ago
@cknight Thank you. Understood