/// import { RedisClientOptions, RedisClientType } from '../client'; import { CommandOptions } from '../client/commands-queue'; import { CommandArguments, CommanderConfig, TypeMapping, RedisArgument, RedisFunctions, RedisModules, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types'; import { EventEmitter } from 'node:events'; import RedisClusterSlots, { NodeAddressMap, ShardNode } from './cluster-slots'; import { RedisClusterMultiCommandType } from './multi-command'; import { PubSubListener, PubSubListeners } from '../client/pub-sub'; import { RedisTcpSocketOptions } from '../client/socket'; import { ClientSideCacheConfig, PooledClientSideCacheProvider } from '../client/cache'; import { WithCommands, WithFunctions, WithModules, WithScripts } from '../client'; interface ClusterCommander extends CommanderConfig { commandOptions?: ClusterCommandOptions; } export type RedisClusterClientOptions = Omit, keyof ClusterCommander>; export interface RedisClusterOptions extends ClusterCommander { /** * Should contain details for some of the cluster nodes that the client will use to discover * the "cluster topology". We recommend including details for at least 3 nodes here. */ rootNodes: Array; /** * Default values used for every client in the cluster. Use this to specify global values, * for example: ACL credentials, timeouts, TLS configuration etc. */ defaults?: Partial; /** * When `true`, `.connect()` will only discover the cluster topology, without actually connecting to all the nodes. * Useful for short-term or PubSub-only connections. */ minimizeConnections?: boolean; /** * When `true`, distribute load by executing readonly commands (such as `GET`, `GEOSEARCH`, etc.) across all cluster nodes. When `false`, only use master nodes. */ useReplicas?: boolean; /** * The maximum number of times a command will be redirected due to `MOVED` or `ASK` errors. */ maxCommandRedirections?: number; /** * Mapping between the addresses in the cluster (see `CLUSTER SHARDS`) and the addresses the client should connect to * Useful when the cluster is running on another network */ nodeAddressMap?: NodeAddressMap; /** * Client Side Caching configuration for the pool. * * Enables Redis Servers and Clients to work together to cache results from commands * sent to a server. The server will notify the client when cached results are no longer valid. * In pooled mode, the cache is shared across all clients in the pool. * * Note: Client Side Caching is only supported with RESP3. * * @example Anonymous cache configuration * ``` * const client = createCluster({ * clientSideCache: { * ttl: 0, * maxEntries: 0, * evictPolicy: "LRU" * }, * minimum: 5 * }); * ``` * * @example Using a controllable cache * ``` * const cache = new BasicPooledClientSideCache({ * ttl: 0, * maxEntries: 0, * evictPolicy: "LRU" * }); * const client = createCluster({ * clientSideCache: cache, * minimum: 5 * }); * ``` */ clientSideCache?: PooledClientSideCacheProvider | ClientSideCacheConfig; } export type RedisClusterType = (RedisCluster & WithCommands & WithModules & WithFunctions & WithScripts); export interface ClusterCommandOptions extends CommandOptions { } export default class RedisCluster extends EventEmitter { #private; static factory(config?: ClusterCommander): (options?: Omit>) => RedisClusterType; static create(options?: RedisClusterOptions): RedisClusterType; readonly _options: RedisClusterOptions; readonly _slots: RedisClusterSlots; private _self; private _commandOptions?; /** * An array of the cluster slots, each slot contain its `master` and `replicas`. * Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific node (master or replica). */ get slots(): import("./cluster-slots").Shard[]; get clientSideCache(): PooledClientSideCacheProvider | undefined; /** * An array of the cluster masters. * Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific master node. */ get masters(): import("./cluster-slots").MasterNode[]; /** * An array of the cluster replicas. * Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific replica node. */ get replicas(): ShardNode[]; /** * A map form a node address (`:`) to its shard, each shard contain its `master` and `replicas`. * Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific node (master or replica). */ get nodeByAddress(): Map | ShardNode>; /** * The current pub/sub node. */ get pubSubNode(): (Omit, "client"> & Required, "client">>) | undefined; get isOpen(): boolean; constructor(options: RedisClusterOptions); duplicate<_M extends RedisModules = M, _F extends RedisFunctions = F, _S extends RedisScripts = S, _RESP extends RespVersions = RESP, _TYPE_MAPPING extends TypeMapping = TYPE_MAPPING>(overrides?: Partial>): RedisClusterType<_M, _F, _S, _RESP, _TYPE_MAPPING>; connect(): Promise>; withCommandOptions, TYPE_MAPPING extends TypeMapping>(options: OPTIONS): RedisClusterType; private _commandOptionsProxy; /** * Override the `typeMapping` command option */ withTypeMapping(typeMapping: TYPE_MAPPING): RedisClusterType; _handleAsk(fn: (client: RedisClientType, opts?: ClusterCommandOptions) => Promise): (client: RedisClientType, options?: ClusterCommandOptions) => Promise; _execute(firstKey: RedisArgument | undefined, isReadonly: boolean | undefined, options: ClusterCommandOptions | undefined, fn: (client: RedisClientType, opts?: ClusterCommandOptions) => Promise): Promise; sendCommand(firstKey: RedisArgument | undefined, isReadonly: boolean | undefined, args: CommandArguments, options?: ClusterCommandOptions): Promise; MULTI(routing?: RedisArgument): RedisClusterMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>; multi: (routing?: RedisArgument) => RedisClusterMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>; SUBSCRIBE(channels: string | Array, listener: PubSubListener, bufferMode?: T): Promise; subscribe: (channels: string | Array, listener: PubSubListener, bufferMode?: T | undefined) => Promise; UNSUBSCRIBE(channels?: string | Array, listener?: PubSubListener, bufferMode?: T): Promise; unsubscribe: (channels?: string | Array, listener?: PubSubListener, bufferMode?: T | undefined) => Promise; PSUBSCRIBE(patterns: string | Array, listener: PubSubListener, bufferMode?: T): Promise; pSubscribe: (patterns: string | Array, listener: PubSubListener, bufferMode?: T | undefined) => Promise; PUNSUBSCRIBE(patterns?: string | Array, listener?: PubSubListener, bufferMode?: T): Promise; pUnsubscribe: (patterns?: string | Array, listener?: PubSubListener | undefined, bufferMode?: T | undefined) => Promise; SSUBSCRIBE(channels: string | Array, listener: PubSubListener, bufferMode?: T): Promise; sSubscribe: (channels: string | Array, listener: PubSubListener, bufferMode?: T | undefined) => Promise; SUNSUBSCRIBE(channels: string | Array, listener?: PubSubListener, bufferMode?: T): Promise; resubscribeAllPubSubListeners(allListeners: PubSubListeners): void; sUnsubscribe: (channels: string | Array, listener?: PubSubListener | undefined, bufferMode?: T | undefined) => Promise; /** * @deprecated Use `close` instead. */ quit(): Promise; /** * @deprecated Use `destroy` instead. */ disconnect(): Promise; close(): Promise; destroy(): void; nodeClient(node: ShardNode): RedisClientType | Promise>; /** * Returns a random node from the cluster. * Userful for running "forward" commands (like PUBLISH) on a random node. */ getRandomNode(): ShardNode; /** * Get a random node from a slot. * Useful for running readonly commands on a slot. */ getSlotRandomNode(slot: number): ShardNode; /** * @deprecated use `.masters` instead * TODO */ getMasters(): import("./cluster-slots").MasterNode[]; /** * @deprecated use `.slots[]` instead * TODO */ getSlotMaster(slot: number): import("./cluster-slots").MasterNode; } export {}; //# sourceMappingURL=index.d.ts.map