@notross/redis-hub
Version:
A minimal connection hub for Redis in Node.js
50 lines • 1.75 kB
TypeScript
import { RedisClientOptions } from 'redis';
import { RedisClient, LoggerConfig, LogResult } from './types';
/**
* Central hub managing named Redis clients. Each
* name gets one shared connection.
*
* Pub/sub roles or per-namespace/user connections
* are just distinct names.
*/
export declare class RedisHub {
private defaultClientName;
private clients;
private clientOptions;
private defaultOptions;
error: any | null;
status: string | null;
connect: (clientId: string) => Promise<RedisClient>;
constructor(loggerConfig?: LoggerConfig);
configureLogger(config?: LoggerConfig): void;
getDefaultClient(): Promise<RedisClient>;
private setDefaultOptions;
/**
* Set the global default Redis options used when no per-client override exists.
* @param options RedisClientOptions
* @param options.defaultClientName string
*/
init(options: RedisClientOptions & {
defaultClientName?: string;
}): void;
getClientById(clientId: string): RedisClient | null;
private createClient;
private conflictingOptions;
/**
* Get or create a named Redis client. Lazy-connects on first call.
* @param clientId Logical name (e.g., "publisher", "user-123-subscriber").
* @param options Optional per-client options; only applied on first creation.
* @returns Connected Redis client.
*/
client(clientId: string, options?: RedisClientOptions): Promise<RedisClient>;
/**
* Disconnects all managed clients and clears internal state.
*/
disconnectAll(): Promise<void>;
/**
* List all logs; useful if logging is disabled
*/
logs(): LogResult[];
private handleClientEvents;
}
//# sourceMappingURL=redis-hub.d.ts.map