Global Key-Value Store.beta

KV Storage

gokv provides a low-latency coordination and consistent KV storage.

import gokv from "https://deno.land/x/gokv@0.0.23/mod.ts";

// get the KV storage
const kv = gokv.Storage();

// for pro users, you can use namespace to separate your data
const kv = gokv.Storage({ namespace: "xxx" });

Try online: https://dash.deno.com/playground/gokv-storage-example

Reading key-value pairs

await kv.get("foo"); // "bar"

// get multiple records
await kv.get(["foo", "baz"]); // { foo: "bar", baz: "qux" }

/*
  If true, then the key/value will not be inserted into the in-memory
  cache. If the key is already in the cache, the cached value will be
  returned, but its last-used time will not be updated. Use this when
  you expect this key will not be used again in the near future.
*/
await kv.get("foo", { noCache: true });

Writing key-value pairs

await kv.put("foo", "bar");

// put multiple records
await kv.put({ foo: "bar", baz: "qux" });

/*
  If true, then the key/value will be discarded from memory as soon as
  it has completed writing to gokv database. Use this when you expect
  this key will not be used again in the near future.
*/
await kv.put("foo", "bar", { noCache: true });

Deleting key-value pairs

await kv.delete("foo");

// delete multiple records
await kv.delete(["foo", "baz"]);

// delete by condition
await kv.delete({ prefix: "user:1:", limit: 10 });
await kv.delete({ start: "foo", end: "baz" });

// same as the option to `put()`, above.
await kv.delete("foo", { noCache: true });

Listing records

// listing all records
await kv.list(); // { foo: "bar", baz: "qux" }

// listing by prefix
await kv.list({ prefix: "user:1:", limit: 10 });

// listing by key range
await kv.list({ start: "foo", end: "baz" });

// listing by reverse
await kv.list({ limit: 10, reverse: true });

// same as the option to `get()`, above.
await kv.list({ noCache: true });