denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.38k stars 5.24k forks source link

[BUG] Deno KV: Using only prefix selector in kv.list, you can't get an exact match key. #21711

Open uga-rosa opened 9 months ago

uga-rosa commented 9 months ago

Version: Deno 1.39.1 (the most recent release)

Summary

The prefix selector of kv.list() cannot get an entry for an exact match key, but it can if start is specified. The start is supposed to be for narrowing down, but it is odd behavior that this would increase the number of entries.

Test code

const db = await Deno.openKv("./test.sqlite3"); for (const d of data) { await db.set(d.key, d.value); }

console.log("only prefix"); for await (const entry of db.list({ prefix: ["data"] })) { console.log(entry.value); }

console.log("prefix and start"); for await (const entry of db.list({ prefix: ["data"], start: ["data"] })) { console.log(entry.value); }

db.close();


## Result

```bash
$ deno run -A --unstable-kv ./test.ts
only prefix
1
prefix and start
0
1
uga-rosa commented 8 months ago

I would at least like a reply as to whether it is a bug or a spec.

iuioiua commented 8 months ago

IIUC, yes, this is expected behaviour. @igorzi or @losfair, is that right?

uga-rosa commented 8 months ago

Neither the fact that you can't get an exact match key with prefix selector alone, nor the fact that you can get it by adding start, is non-trivial behavior, nor can it be read from the documentation. If this is a specification, then the documentation needs to be improved.

https://deno.land/api@v1.40.2?s=Deno.Kv&unstable=&p=prototype.list

lucacasonato commented 3 months ago

This is a bug. The second case should return the same result as the first.