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

const store = new UpstashRedisStore({
client: new Redis({
url: "your-upstash-redis-url",
token: "your-upstash-redis-token",
}),
});
await store.mset([
["message:id:0", "encoded-ai-message"],
["message:id:1", "encoded-human-message"],
]);
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 (view full)

  • Toolkit<string, Uint8Array>
    • UpstashRedisStore

Constructors

Properties

client: Redis
yieldKeysScanBatchSize: number = 1000
namespace?: string

Methods

  • Gets multiple keys from the Upstash 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 Upstash 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.

  • Yields keys from the Upstash Redis database.

    Parameters

    • Optionalprefix: string

      Optional prefix to filter the keys. A wildcard (*) is always appended to the end.

    Returns AsyncGenerator<string, any, unknown>

    An AsyncGenerator that yields keys from the Upstash Redis database.