import KeyvRedis from '@keyv/redis'; import type { ClusterNode, ClusterOptions } from 'ioredis'; export interface ClusterConfig { nodes: ClusterNode[]; options?: ClusterOptions; } /** * A lazy-loading Redis store for Keyv. * Defers Redis connection until the first operation is performed. * This prevents connection exhaustion during Cloud Run/serverless deployments * where old and new containers may briefly run simultaneously. * * Supports both standalone Redis (via connection string) and Redis Cluster (via clusterConfig). * * @example * ```typescript * // Standalone * const store = new LazyRedisStore('redis://localhost:6379') * * // Cluster * const store = new LazyRedisStore('cluster', { * nodes: [{ host: '10.0.0.2', port: 6379 }], * options: { redisOptions: { password: 'secret', tls: { rejectUnauthorized: false } } } * }) * ``` */ export declare class LazyRedisStore { private connectionString; private pool; private _store; private _connecting; private _namespace; private _clusterConfig?; /** * Opts property for Keyv compatibility. * Keyv checks for store.opts to detect if iteration is supported. * It looks for opts.dialect or opts.url containing 'redis', 'postgres', etc. * @see https://github.com/jaredwray/keyv/blob/main/packages/keyv/src/index.ts */ readonly opts: { dialect: string; url: string; }; constructor(connectionString: string, clusterConfig?: ClusterConfig); /** * Namespace property for Keyv compatibility. * Keyv sets this after construction to enable namespace-scoped operations. * We forward it to the underlying KeyvRedis store when connected. */ get namespace(): string | undefined; set namespace(value: string | undefined); /** * Get the underlying KeyvRedis store, creating connection if needed. * Uses a promise to ensure only one connection attempt happens even * if multiple operations are called simultaneously. */ getStore(): Promise; get(key: string): Promise; getMany(keys: string[]): Promise; set(key: string, value: any, ttl?: number): Promise; delete(key: string): Promise; deleteMany(keys: string[]): Promise; clear(): Promise; has(key: string): Promise; /** * Iterator for Keyv - returns an async iterable iterator. * This method is defined to tell Keyv that iteration is supported. */ iterator(namespace?: string): AsyncGenerator<[string, any]>; /** * Check if the store is connected */ isConnected(): boolean; /** * Get the connection string (for pool management) */ getConnectionString(): string; /** * Disconnect the underlying store */ disconnect(): Promise; }