Class that extends the BaseStore class to interact with a Vercel KV database. It provides methods for getting, setting, and deleting data, as well as yielding keys from the database.

const store = new VercelKVStore({
client: getClient(),
});
await store.mset([
{ key: "message:id:0", value: "encoded message 0" },
{ key: "message:id:1", value: "encoded message 1" },
]);
const retrievedMessages = await store.mget(["message:id:0", "message:id:1"]);
const yieldedKeys = [];
for await (const key of store.yieldKeys("message:id:")) {
yieldedKeys.push(key);
}
await store.mdelete(yieldedKeys);

Hierarchy

  • BaseStore<string, Uint8Array>
    • VercelKVStore

Constructors

  • Parameters

    • Optionalfields: {
          client?: VercelKV;
          namespace?: string;
          ttl?: number;
          yieldKeysScanBatchSize?: number;
      }
      • Optionalclient?: VercelKV
      • Optionalnamespace?: string
      • Optionalttl?: number
      • OptionalyieldKeysScanBatchSize?: number

    Returns VercelKVStore

Properties

client: VercelKV
namespace?: string
ttl?: number
yieldKeysScanBatchSize: number = 1000

Methods

  • Deletes multiple keys from the Redis database.

    Parameters

    • keys: string[]

      Array of keys to be deleted.

    Returns Promise<void>

    Promise that resolves when all keys have been deleted.

  • Gets multiple keys from the Redis database.

    Parameters

    • keys: string[]

      Array of keys to be retrieved.

    Returns Promise<(undefined | Uint8Array)[]>

    An array of retrieved values.

  • Sets multiple keys in the Redis database.

    Parameters

    • keyValuePairs: [string, Uint8Array][]

      Array of key-value pairs to be set.

    Returns Promise<void>

    Promise that resolves when all keys have been set.

  • Returns Serialized

  • Yields keys from the Redis database.

    Parameters

    • Optionalprefix: string

      Optional prefix to filter the keys.

    Returns AsyncGenerator<string, any, unknown>

    An AsyncGenerator that yields keys from the Redis database.