@fedify/redis
Version:
Redis drivers for Fedify
50 lines (49 loc) • 1.47 kB
TypeScript
import { Temporal } from "@js-temporal/polyfill";
import { Codec } from "./codec.js";
import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
import { Redis, RedisKey } from "ioredis";
//#region src/kv.d.ts
/**
* Options for {@link RedisKvStore} class.
*/
interface RedisKvStoreOptions {
/**
* The prefix to use for all keys in the key–value store in Redis.
* Defaults to `"fedify::"`.
*/
keyPrefix?: RedisKey;
/**
* The codec to use for encoding and decoding values in the key–value store.
* Defaults to {@link JsonCodec}.
*/
codec?: Codec;
}
/**
* A key–value store that uses Redis as the underlying storage.
*
* @example
* ```ts ignore
* import { createFederation } from "@fedify/fedify";
* import { RedisKvStore } from "@fedify/redis";
* import { Redis } from "ioredis";
*
* const federation = createFederation({
* // ...
* kv: new RedisKvStore(new Redis()),
* });
* ```
*/
declare class RedisKvStore implements KvStore {
#private;
/**
* Creates a new Redis key–value store.
* @param redis The Redis client to use.
* @param options The options for the key–value store.
*/
constructor(redis: Redis, options?: RedisKvStoreOptions);
get<T = unknown>(key: KvKey): Promise<T | undefined>;
set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
delete(key: KvKey): Promise<void>;
}
//#endregion
export { RedisKvStore, RedisKvStoreOptions };