import { OnModuleDestroy } from '@nestjs/common'; import { ICacheMetricsRecorder } from '../ICacheMetricsRecorder'; import { ICacheStats } from '../ICacheStats'; import { ILayeredCache } from '../interfaces/ILayeredCache'; /** * Configuration options for {@link RedisLayeredCache}. * * @public * @template TValue The type of values stored in this cache. */ export interface IRedisLayeredCacheOptions { /** * Redis connection URL (e.g. `redis://localhost:6379`). * * @public */ url: string; /** * Key prefix applied to all Redis keys managed by this cache instance. * * @public */ keyPrefix: string; /** * Optional TTL in seconds applied to every stored entry. * * @public */ ttlSeconds?: number; /** * Custom serialization function. Defaults to `JSON.stringify`. * * @public */ serialize?: (value: TValue) => string; /** * Custom deserialization function. Defaults to `JSON.parse`. * * @public */ deserialize?: (raw: string) => TValue; /** * Optional metrics recorder forwarded cache operation statistics. * * @public */ metricsRecorder?: ICacheMetricsRecorder; /** * An optional name / label for the cache instance, used in metrics. * Defaults to `'redis'`. * * @public */ cacheName?: string; } /** * Redis-backed layered cache implementation. Falls back to an asynchronous * loader function when the requested key is not present in Redis. * * @remarks * Synchronous methods (`get`, `set`, `invalidate`) throw because Redis * is inherently asynchronous. Use the `*Async` variants instead. * * @public * @template TKey The type of the cache keys. * @template TValue The type of the cache values. */ export declare class RedisLayeredCache implements ILayeredCache, OnModuleDestroy { private readonly _loadFn; private readonly _logger; private readonly _redis; private readonly _options; private readonly _inflight; private _hits; private _misses; private _loads; private _loadErrors; private readonly _metrics; private readonly _cacheName; /** * Initializes a new instance of the {@link RedisLayeredCache} class. * * @param loadFn - Async loader invoked on cache misses. * @param options - Redis connection and cache behaviour configuration. */ constructor(loadFn: (key: TKey) => Promise, options: IRedisLayeredCacheOptions); /** * Not supported - Redis is inherently asynchronous. * * @throws Always throws. Use {@link getAsync} instead. */ get(key: TKey): TValue | undefined; /** @inheritdoc */ getAsync(key: TKey): Promise; /** * Not supported - Redis is inherently asynchronous. * * @throws Always throws. Use {@link setAsync} instead. */ set(key: TKey, value: TValue): void; /** @inheritdoc */ setAsync(key: TKey, value: TValue): Promise; /** @inheritdoc */ warm(key: TKey): Promise; /** * Not supported - Redis is inherently asynchronous. * * @throws Always throws. Use {@link invalidateAsync} instead. */ invalidate(key: TKey): void; /** @inheritdoc */ invalidateAsync(key: TKey): Promise; /** @inheritdoc */ stats(): ICacheStats; /** * Gracefully disconnects the Redis client when the NestJS module is destroyed. */ onModuleDestroy(): Promise; private _safeLoad; private _formatKey; private _serialize; private _deserialize; }