///
import { EventEmitter } from 'node:events';
import { CommandArguments, RedisFunctions, RedisModules, RedisScripts, ReplyUnion, RespVersions, TypeMapping } from '../RESP/types';
import RedisClient, { RedisClientType } from '../client';
import { CommandOptions } from '../client/commands-queue';
import { RedisNode, RedisSentinelClientType, RedisSentinelOptions, RedisSentinelType, SentinelCommander } from './types';
import { RedisMultiQueuedCommand } from '../multi-command';
import { RedisSentinelMultiCommandType } from './multi-commands';
import { PubSubListener } from '../client/pub-sub';
import { RedisVariadicArgument } from '../commands/generic-transformers';
import { PooledClientSideCacheProvider } from '../client/cache';
interface ClientInfo {
id: number;
}
export declare class RedisSentinelClient {
#private;
readonly _self: RedisSentinelClient;
/**
* Indicates if the client connection is open
*
* @returns `true` if the client connection is open, `false` otherwise
*/
get isOpen(): boolean;
/**
* Indicates if the client connection is ready to accept commands
*
* @returns `true` if the client connection is ready, `false` otherwise
*/
get isReady(): boolean;
/**
* Gets the command options configured for this client
*
* @returns The command options for this client or `undefined` if none were set
*/
get commandOptions(): CommandOptions | undefined;
constructor(internal: RedisSentinelInternal, clientInfo: ClientInfo, commandOptions?: CommandOptions);
static factory(config?: SentinelCommander): (internal: RedisSentinelInternal, clientInfo: ClientInfo, commandOptions?: CommandOptions) => RedisSentinelClientType;
static create(options: RedisSentinelOptions, internal: RedisSentinelInternal, clientInfo: ClientInfo, commandOptions?: CommandOptions): RedisSentinelClientType;
withCommandOptions, TYPE_MAPPING extends TypeMapping>(options: OPTIONS): RedisSentinelClientType;
private _commandOptionsProxy;
/**
* Override the `typeMapping` command option
*/
withTypeMapping(typeMapping: TYPE_MAPPING): RedisSentinelClientType;
_execute(isReadonly: boolean | undefined, fn: (client: RedisClient) => Promise): Promise;
sendCommand(isReadonly: boolean | undefined, args: CommandArguments, options?: CommandOptions): Promise;
/**
* @internal
*/
_executePipeline(isReadonly: boolean | undefined, commands: Array): Promise;
/**f
* @internal
*/
_executeMulti(isReadonly: boolean | undefined, commands: Array): Promise;
MULTI(): RedisSentinelMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>;
multi: () => RedisSentinelMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>;
WATCH(key: RedisVariadicArgument): Promise<"OK">;
watch: (key: RedisVariadicArgument) => Promise<"OK">;
UNWATCH(): Promise<"OK">;
unwatch: () => Promise<"OK">;
/**
* Releases the client lease back to the pool
*
* After calling this method, the client instance should no longer be used as it
* will be returned to the client pool and may be given to other operations.
*
* @returns A promise that resolves when the client is ready to be reused, or undefined
* if the client was immediately ready
* @throws Error if the lease has already been released
*/
release(): Promise | undefined;
}
export default class RedisSentinel extends EventEmitter {
#private;
readonly _self: RedisSentinel;
/**
* Indicates if the sentinel connection is open
*
* @returns `true` if the sentinel connection is open, `false` otherwise
*/
get isOpen(): boolean;
/**
* Indicates if the sentinel connection is ready to accept commands
*
* @returns `true` if the sentinel connection is ready, `false` otherwise
*/
get isReady(): boolean;
get commandOptions(): CommandOptions | undefined;
get clientSideCache(): PooledClientSideCacheProvider | undefined;
constructor(options: RedisSentinelOptions);
static factory(config?: SentinelCommander): (options: Omit>) => RedisSentinelType;
static create(options: RedisSentinelOptions): RedisSentinelType;
withCommandOptions, TYPE_MAPPING extends TypeMapping>(options: OPTIONS): RedisSentinelType;
private _commandOptionsProxy;
/**
* Override the `typeMapping` command option
*/
withTypeMapping(typeMapping: TYPE_MAPPING): RedisSentinelType;
connect(): Promise>;
_execute(isReadonly: boolean | undefined, fn: (client: RedisClient) => Promise): Promise;
use(fn: (sentinelClient: RedisSentinelClientType) => Promise): Promise;
sendCommand(isReadonly: boolean | undefined, args: CommandArguments, options?: CommandOptions): Promise;
/**
* @internal
*/
_executePipeline(isReadonly: boolean | undefined, commands: Array): Promise;
/**f
* @internal
*/
_executeMulti(isReadonly: boolean | undefined, commands: Array): Promise;
MULTI(): RedisSentinelMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>;
multi: () => RedisSentinelMultiCommandType<[], M, F, S, RESP, TYPE_MAPPING>;
close(): Promise;
destroy(): Promise;
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;
/**
* Acquires a master client lease for exclusive operations
*
* Used when multiple commands need to run on an exclusive client (for example, using `WATCH/MULTI/EXEC`).
* The returned client must be released after use with the `release()` method.
*
* @returns A promise that resolves to a Redis client connected to the master node
* @example
* ```javascript
* const clientLease = await sentinel.acquire();
*
* try {
* await clientLease.watch('key');
* const resp = await clientLease.multi()
* .get('key')
* .exec();
* } finally {
* clientLease.release();
* }
* ```
*/
acquire(): Promise>;
getSentinelNode(): RedisNode | undefined;
getMasterNode(): RedisNode | undefined;
getReplicaNodes(): Map;
setTracer(tracer?: Array): void;
}
declare class RedisSentinelInternal extends EventEmitter {
#private;
get isOpen(): boolean;
get isReady(): boolean;
get useReplicas(): boolean;
get clientSideCache(): PooledClientSideCacheProvider | undefined;
constructor(options: RedisSentinelOptions);
/**
* Gets a client lease from the master client pool
*
* @returns A client info object or a promise that resolves to a client info object
* when a client becomes available
*/
getClientLease(): ClientInfo | Promise;
/**
* Releases a client lease back to the pool
*
* If the client was used for a transaction that might have left it in a dirty state,
* it will be reset before being returned to the pool.
*
* @param clientInfo The client info object representing the client to release
* @returns A promise that resolves when the client is ready to be reused, or undefined
* if the client was immediately ready or no longer exists
*/
releaseClientLease(clientInfo: ClientInfo): Promise | undefined;
connect(): Promise;
execute(fn: (client: RedisClientType) => Promise, clientInfo?: ClientInfo): Promise;
close(): Promise;
destroy(): Promise;
subscribe(channels: string | Array, listener: PubSubListener, bufferMode?: T): Promise;
unsubscribe(channels?: string | Array, listener?: PubSubListener, bufferMode?: T): Promise;
pSubscribe(patterns: string | Array, listener: PubSubListener, bufferMode?: T): Promise;
pUnsubscribe(patterns?: string | Array, listener?: PubSubListener, bufferMode?: T): Promise;
observe(): Promise<{
sentinelConnected: RedisNode;
sentinelData: {
[x: string]: string;
}[];
masterData: {
[x: string]: string;
};
replicaData: {
[x: string]: string;
}[];
currentMaster: RedisNode | undefined;
currentReplicas: Map;
currentSentinel: RedisNode | undefined;
replicaPoolSize: number;
useReplicas: boolean;
}>;
analyze(observed: Awaited["observe"]>>): {
sentinelList: RedisNode[];
epoch: number;
sentinelToOpen: RedisNode | undefined;
masterToOpen: RedisNode | undefined;
replicasToClose: RedisNode[];
replicasToOpen: Map;
};
transform(analyzed: ReturnType["analyze"]>): Promise;
getMasterNode(): RedisNode | undefined;
getSentinelNode(): RedisNode | undefined;
getReplicaNodes(): Map;
setTracer(tracer?: Array): void;
}
export declare class RedisSentinelFactory extends EventEmitter {
#private;
options: RedisSentinelOptions;
constructor(options: RedisSentinelOptions);
updateSentinelRootNodes(): Promise;
getMasterNode(): Promise;
getMasterClient(): Promise>;
getReplicaNodes(): Promise;
getReplicaClient(): Promise>;
}
export {};
//# sourceMappingURL=index.d.ts.map