/// import { CallbackFunction, ICommand, CommandParameter } from "./types"; interface ICommandOptions { /** * Set the encoding of the reply, by default buffer will be returned. * * @type {(string | null)} * @memberof ICommandOptions */ replyEncoding?: string | null; errorStack?: string; keyPrefix?: string; /** * Force the command to be readOnly so it will also execute on slaves */ readOnly?: boolean; } declare type ArgumentTransformer = (args: any[]) => any[]; declare type ReplyTransformer = (reply: any) => any; export interface ICommandNameFlags { VALID_IN_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "unsubscribe", "punsubscribe", "ping", "quit"]; VALID_IN_MONITOR_MODE: ["monitor", "auth"]; ENTER_SUBSCRIBER_MODE: ["subscribe", "psubscribe"]; EXIT_SUBSCRIBER_MODE: ["unsubscribe", "punsubscribe"]; WILL_DISCONNECT: ["quit"]; } /** * Command instance * * It's rare that you need to create a Command instance yourself. * * @export * @class Command * * @example * ```js * var infoCommand = new Command('info', null, function (err, result) { * console.log('result', result); * }); * * redis.sendCommand(infoCommand); * * // When no callback provided, Command instance will have a `promise` property, * // which will resolve/reject with the result of the command. * var getCommand = new Command('get', ['foo']); * getCommand.promise.then(function (result) { * console.log('result', result); * }); * ``` * @see {@link Redis#sendCommand} which can send a Command instance to Redis */ export default class Command implements ICommand { name: string; static FLAGS: { [key in keyof ICommandNameFlags]: ICommandNameFlags[key]; }; private static flagMap?; private static getFlagMap; /** * Check whether the command has the flag * * @param {string} flagName * @param {string} commandName * @return {boolean} */ static checkFlag(flagName: T, commandName: string): commandName is ICommandNameFlags[T][number]; private static _transformer; static setArgumentTransformer(name: string, func: ArgumentTransformer): void; static setReplyTransformer(name: string, func: ReplyTransformer): void; ignore?: boolean; isReadOnly?: boolean; private replyEncoding; private errorStack; args: CommandParameter[]; private callback; private transformed; isCustomCommand: boolean; inTransaction: boolean; pipelineIndex?: number; private slot?; private keys?; reject: (err: Error) => void; resolve: (result: any) => void; promise: Promise; /** * Creates an instance of Command. * @param {string} name Command name * @param {(Array)} [args=[]] An array of command arguments * @param {ICommandOptions} [options={}] * @param {CallbackFunction} [callback] The callback that handles the response. * If omit, the response will be handled via Promise * @memberof Command */ constructor(name: string, args?: Array>, options?: ICommandOptions, callback?: CallbackFunction); private initPromise; getSlot(): number; getKeys(): Array; /** * Iterate through the command arguments that are considered keys. * * @param {Function} [transform=(key) => key] The transformation that should be applied to * each key. The transformations will persist. * @returns {string[]} The keys of the command. * @memberof Command */ private _iterateKeys; /** * Convert command to writable buffer or string * * @return {string|Buffer} * @see {@link Redis#sendCommand} * @public */ toWritable(): string | Buffer; stringifyArguments(): void; /** * Convert the value from buffer to the target encoding. * * @private * @param {Function} resolve The resolve function of the Promise * @returns {Function} A funtion to transform and resolve a value * @memberof Command */ private _convertValue; /** * Convert buffer/buffer[] to string/string[], * and apply reply transformer. * * @memberof Command */ transformReply(result: Buffer | Buffer[]): string | string[] | Buffer | Buffer[]; } export {};