UNPKG

@o1s/redis-testbench

Version:

Redis (single instance and cluster) test bench

63 lines (62 loc) 1.97 kB
import IORedis from "ioredis"; /** * If only the ports are provided, we default host to 127.0.0.1, * and assume services are running inside docker-compose. */ export interface ClusterWithNATClientOptions { ports: number[]; } /** * If hosts are provided, we are running inside redis-testbench' provided * redis cluster. * Ports default to 6379. */ export interface ClusterWithoutNATClientOptions { hosts: string[]; } /** * Non-cluster redis client option. */ export interface RedisClientOptions { host?: string; port?: number; } export declare type ClientOptions = { /** * If truthy, commands will not get sent to replicas. */ noReplicas?: boolean; } & (RedisClientOptions | ClusterWithoutNATClientOptions | ClusterWithNATClientOptions); /** * Returns `buildClient` options from environment variables: * * Accessing redis cluster from outside of docker-compose: * - REDIS_PORTS=6380,6381,6382,6383,6384,6385 * * Accessing redis cluster from inside the docker-compose: * - REDIS_HOSTS=redis-node-0 * * Accessing redis instance from outside of docker-compose: * - REDIS_PORT=6379 * * Accessing redis instance from inside of docker-compose: * - REDIS_PORT=6379 */ export declare const buildOptionsFromEnv: () => ClientOptions; /** * Create either a redis or redis cluster client (from IORedis package). * If a redis cluster client is requested, IORedis natMap is resolved. * * Accessing redis cluster from outside of docker-compose: * - buildClient({ ports: [ 6380, 6381, 6382, 6383, 6384, 6385 ] }) * * Accessing redis cluster from inside the docker-compose: * - buildClient({ hosts: [ 'redis-node-0' ] }) * * Accessing redis instance from outside of docker-compose: * - buildClient({ port: 6379 }) * * Accessing redis instance from inside of docker-compose: * - buildClient({ port: 6379 }) */ export declare const buildClient: (options: ClientOptions) => Promise<IORedis.Redis | IORedis.Cluster>;