UNPKG

@fedify/redis

Version:

Redis drivers for Fedify

67 lines (66 loc) 1.98 kB
import { Temporal } from "@js-temporal/polyfill"; import { Codec } from "./codec.js"; import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify"; import { Cluster, 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, Cluster } from "ioredis"; * * // Using a standalone Redis instance: * const federation = createFederation({ * // ... * kv: new RedisKvStore(new Redis()), * }); * * // Using a Redis Cluster: * const cluster = new Cluster([ * { host: "127.0.0.1", port: 7000 }, * { host: "127.0.0.1", port: 7001 }, * { host: "127.0.0.1", port: 7002 }, * ]); * const federation = createFederation({ * // ... * kv: new RedisKvStore(cluster), * }); * ``` */ declare class RedisKvStore implements KvStore { #private; /** * Creates a new Redis key–value store. * @param redis The Redis client (standalone or cluster) to use. * @param options The options for the key–value store. */ constructor(redis: Redis | Cluster, 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>; /** * {@inheritDoc KvStore.list} * @since 1.10.0 */ list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>; } //#endregion export { RedisKvStore, RedisKvStoreOptions };