import KeyvRedis from '@keyv/redis'; import { type ClusterNode, type ClusterOptions } from 'ioredis'; /** * Singleton connection pool for Redis connections. * Ensures multiple Cache instances pointing to the same Redis instance * share the same underlying Redis client, avoiding connection exhaustion. * Each Cache gets its own KeyvRedis wrapper but shares the client. */ export declare class RedisConnectionPool { private static instance; private pool; private constructor(); static getInstance(): RedisConnectionPool; /** * Get a Redis store from the pool. Creates a new KeyvRedis instance that uses * a shared Redis client if one exists, or creates a new client if not. * * For `rediss://` (TLS) URLs, automatically adds `tls: { rejectUnauthorized: false }` * so that connections to Redis instances using non-public CA certificates (e.g., GCP * Memorystore with Google-managed certs) work without disabling TLS validation * process-wide via NODE_TLS_REJECT_UNAUTHORIZED. * * @param connectionString The Redis connection string * @returns KeyvRedis store instance */ getConnection(connectionString: string): KeyvRedis; /** * Get a Redis store backed by an ioredis Cluster instance. * Pools the underlying Cluster connection by a key derived from the sorted node list. * * IMPORTANT: Uses `useRedisSets: false` because MULTI/EXEC (used by the default * useRedisSets: true) is not supported across slots in Redis Cluster. * * @param nodes Cluster seed nodes * @param options ioredis ClusterOptions * @returns KeyvRedis store wrapping the shared Cluster instance */ getClusterConnection(nodes: ClusterNode[], options?: ClusterOptions): KeyvRedis; /** * Release a Redis connection. When reference count reaches 0, * the connection is kept in the pool for reuse. * @param connectionString The Redis connection string */ releaseConnection(connectionString: string): void; /** * Disconnect and remove a connection from the pool. * This should be called when you're certain no more instances will need this connection. * @param connectionString The Redis connection string */ disconnect(connectionString: string): Promise; /** * Disconnect all connections in the pool. * Useful for cleanup during application shutdown. */ disconnectAll(): Promise; /** * Get the reference count for a connection. * Useful for testing and debugging. * @param connectionString The Redis connection string */ getRefCount(connectionString: string): number; /** * Get the number of connections in the pool. * Useful for testing and debugging. */ getPoolSize(): number; /** * Clear the pool without disconnecting. * Only use this for testing purposes. */ clearPool(): void; }