UNPKG

@valkey/client

Version:

The source code and documentation for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.

148 lines (147 loc) 9.03 kB
/// <reference types="node" /> import COMMANDS from "./commands"; import { ValkeyCommand, ValkeyCommandArguments, ValkeyCommandRawReply, ValkeyCommandReply, ValkeyFunctions, ValkeyModules, ValkeyExtensions, ValkeyScript, ValkeyScripts, ValkeyCommandSignature, ConvertArgumentType, ValkeyFunction, ExcludeMappedString } from "../commands"; import { ValkeySocketOptions } from "./socket"; import { QueueCommandOptions } from "./commands-queue"; import { ValkeyClientMultiCommandType } from "./multi-command"; import { ValkeyMultiQueuedCommand } from "../multi-command"; import { EventEmitter } from "events"; import { CommandOptions } from "../command-options"; import { ScanOptions, ZMember } from "../commands/generic-transformers"; import { ScanCommandOptions } from "../commands/SCAN"; import { HScanTuple } from "../commands/HSCAN"; import { Options as PoolOptions } from "generic-pool"; import { PubSubType, PubSubListener, PubSubTypeListeners, ChannelListeners } from "./pub-sub"; export interface ValkeyClientOptions<M extends ValkeyModules = ValkeyModules, F extends ValkeyFunctions = ValkeyFunctions, S extends ValkeyScripts = ValkeyScripts> extends ValkeyExtensions<M, F, S> { /** * `redis[s]://[[username][:password]@][host][:port][/db-number]` * See [`redis`](https://www.iana.org/assignments/uri-schemes/prov/redis) and [`rediss`](https://www.iana.org/assignments/uri-schemes/prov/rediss) IANA registration for more details */ url?: string; /** * Socket connection properties */ socket?: ValkeySocketOptions; /** * ACL username ([see ACL guide](https://redis.io/topics/acl)) */ username?: string; /** * ACL password or the old "--requirepass" password */ password?: string; /** * Client name ([see `CLIENT SETNAME`](https://redis.io/commands/client-setname)) */ name?: string; /** * Valkey database number (see [`SELECT`](https://redis.io/commands/select) command) */ database?: number; /** * Maximum length of the client's internal command queue */ commandsQueueMaxLength?: number; /** * When `true`, commands are rejected when the client is reconnecting. * When `false`, commands are queued for execution after reconnection. */ disableOfflineQueue?: boolean; /** * Connect in [`READONLY`](https://redis.io/commands/readonly) mode */ readonly?: boolean; legacyMode?: boolean; isolationPoolOptions?: PoolOptions; /** * Send `PING` command at interval (in ms). * Useful with Valkey deployments that do not use TCP Keep-Alive. */ pingInterval?: number; /** * If set to true, disables sending client identifier (user-agent like message) to the redis server */ disableClientInfo?: boolean; /** * Tag to append to library name that is sent to the Valkey server */ clientInfoTag?: string; } type WithCommands = { [P in keyof typeof COMMANDS]: ValkeyCommandSignature<(typeof COMMANDS)[P]>; }; export type WithModules<M extends ValkeyModules> = { [P in keyof M as ExcludeMappedString<P>]: { [C in keyof M[P] as ExcludeMappedString<C>]: ValkeyCommandSignature<M[P][C]>; }; }; export type WithFunctions<F extends ValkeyFunctions> = { [P in keyof F as ExcludeMappedString<P>]: { [FF in keyof F[P] as ExcludeMappedString<FF>]: ValkeyCommandSignature<F[P][FF]>; }; }; export type WithScripts<S extends ValkeyScripts> = { [P in keyof S as ExcludeMappedString<P>]: ValkeyCommandSignature<S[P]>; }; export type ValkeyClientType<M extends ValkeyModules = Record<string, never>, F extends ValkeyFunctions = Record<string, never>, S extends ValkeyScripts = Record<string, never>> = ValkeyClient<M, F, S> & WithCommands & WithModules<M> & WithFunctions<F> & WithScripts<S>; export type InstantiableValkeyClient<M extends ValkeyModules, F extends ValkeyFunctions, S extends ValkeyScripts> = new (options?: ValkeyClientOptions<M, F, S>) => ValkeyClientType<M, F, S>; export interface ClientCommandOptions extends QueueCommandOptions { isolated?: boolean; } export default class ValkeyClient<M extends ValkeyModules, F extends ValkeyFunctions, S extends ValkeyScripts> extends EventEmitter { #private; static commandOptions<T extends ClientCommandOptions>(options: T): CommandOptions<T>; commandOptions: typeof ValkeyClient.commandOptions; static extend<M extends ValkeyModules, F extends ValkeyFunctions, S extends ValkeyScripts>(extensions?: ValkeyExtensions<M, F, S>): InstantiableValkeyClient<M, F, S>; static create<M extends ValkeyModules, F extends ValkeyFunctions, S extends ValkeyScripts>(options?: ValkeyClientOptions<M, F, S>): ValkeyClientType<M, F, S>; static parseURL(url: string): ValkeyClientOptions; get options(): ValkeyClientOptions<M, F, S> | undefined; get isOpen(): boolean; get isReady(): boolean; get isPubSubActive(): boolean; get v4(): Record<string, any>; constructor(options?: ValkeyClientOptions<M, F, S>); duplicate(overrides?: Partial<ValkeyClientOptions<M, F, S>>): ValkeyClientType<M, F, S>; connect(): Promise<ValkeyClientType<M, F, S>>; commandsExecutor<C extends ValkeyCommand>(command: C, args: Array<unknown>): Promise<ValkeyCommandReply<C>>; sendCommand<T = ValkeyCommandRawReply>(args: ValkeyCommandArguments, options?: ClientCommandOptions): Promise<T>; functionsExecuter<F extends ValkeyFunction>(fn: F, args: Array<unknown>, name: string): Promise<ValkeyCommandReply<F>>; executeFunction(name: string, fn: ValkeyFunction, args: ValkeyCommandArguments, options?: ClientCommandOptions): Promise<ValkeyCommandRawReply>; scriptsExecuter<S extends ValkeyScript>(script: S, args: Array<unknown>): Promise<ValkeyCommandReply<S>>; executeScript(script: ValkeyScript, args: ValkeyCommandArguments, options?: ClientCommandOptions): Promise<ValkeyCommandRawReply>; SELECT(db: number): Promise<void>; SELECT(options: CommandOptions<ClientCommandOptions>, db: number): Promise<void>; select: { (db: number): Promise<void>; (options: CommandOptions<ClientCommandOptions>, db: number): Promise<void>; }; SUBSCRIBE<T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>; subscribe: <T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T) => Promise<void>; UNSUBSCRIBE<T extends boolean = false>(channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>; unsubscribe: <T extends boolean = false>(channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T) => Promise<void>; PSUBSCRIBE<T extends boolean = false>(patterns: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>; pSubscribe: <T extends boolean = false>(patterns: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T) => Promise<void>; PUNSUBSCRIBE<T extends boolean = false>(patterns?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>; pUnsubscribe: <T extends boolean = false>(patterns?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T) => Promise<void>; SSUBSCRIBE<T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>; sSubscribe: <T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T) => Promise<void>; SUNSUBSCRIBE<T extends boolean = false>(channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>; sUnsubscribe: <T extends boolean = false>(channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T) => Promise<void>; getPubSubListeners(type: PubSubType): PubSubTypeListeners; extendPubSubChannelListeners(type: PubSubType, channel: string, listeners: ChannelListeners): Promise<void>; extendPubSubListeners(type: PubSubType, listeners: PubSubTypeListeners): Promise<void>; QUIT(): Promise<string>; quit: () => Promise<string>; executeIsolated<T>(fn: (client: ValkeyClientType<M, F, S>) => T | Promise<T>): Promise<T>; MULTI(): ValkeyClientMultiCommandType<M, F, S>; multi: () => ValkeyClientMultiCommandType<M, F, S>; multiExecutor(commands: Array<ValkeyMultiQueuedCommand>, selectedDB?: number, chainId?: symbol): Promise<Array<ValkeyCommandRawReply>>; scanIterator(options?: ScanCommandOptions): AsyncIterable<string>; hScanIterator(key: string, options?: ScanOptions): AsyncIterable<ConvertArgumentType<HScanTuple, string>>; sScanIterator(key: string, options?: ScanOptions): AsyncIterable<string>; zScanIterator(key: string, options?: ScanOptions): AsyncIterable<ConvertArgumentType<ZMember, string>>; disconnect(): Promise<void>; ref(): void; unref(): void; } export {};