import { Pool, Options as PoolOptions } from 'generic-pool'; import { ClientOpts as RedisOptions, RedisClient } from 'redis'; import { Logger } from './helpers'; /** * @alias RedisPoolStatus */ export interface RedisPoolStatus { name: string; size: number; available: number; pending: number; } /** * RedisPool */ declare class RedisPool { name: string; redisOptions: RedisOptions; poolOptions: PoolOptions; logger: { debug: Function; log: Function; info: Function; warn: Function; error: Function; }; pool: Pool; /** * @constructor * @param options * @param options.name - Name your pool * @param * @param * @param options.logger - Inject your custom logger */ constructor({ name, redisOptions, poolOptions, logger }: { name?: string; redisOptions: RedisOptions; poolOptions?: PoolOptions; logger?: Logger; }); /** * Send redis instructions * @async * @param commandName - Name of the command * @param commandArgs - Args sent to the command * @returns Promise resolve with the result or Error */ sendCommand(commandName: string, commandArgs?: any[]): Promise; /** * Acquire a Redis connection and use an optional priority. * @async * @param priority - priority list number * @param * @returns Promise resolve with the connection or Error */ acquire(priority?: number, db?: number): Promise; /** * Release a Redis connection to the pool. * @async * @param client - Redis connection * @returns void */ release(client?: RedisClient): Promise; /** * Destroy a Redis connection. * @async * @param client - Redis connection * @returns void */ destroy(client?: RedisClient): Promise; /** * Drains the connection pool and call the callback id provided. * @async * @returns Promise */ drain(): Promise; /** * Returns factory.name for this pool * * @returns Name of the pool */ getName(): string; /** * Returns this.redisOptions for this pool * * @returns redis options given */ getRedisOptions(): RedisOptions; /** * Returns this.poolOptions for this pool * * @returns pool options given */ getPoolOptions(): PoolOptions; /** * Returns size of the pool * * @returns size of the pool */ getPoolSize(): number; /** * Returns available connections count of the pool * * @returns available connections count of the pool */ availableCount(): number; /** * Returns pending connections count of the pool * * @returns pending connections count of the pool */ pendingCount(): number; /** * Returns pool status and stats * * @returns pool status and stats */ status(): RedisPoolStatus; } export default RedisPool;