Class Command

Command instance

It's rare that you need to create a Command instance yourself.

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);
});

Implements

  • Respondable

Constructors

  • Creates an instance of Command.

    Parameters

    • name: string

      Command name

    • args: ArgumentType[] = []

      An array of command arguments

    • options: CommandOptions = {}
    • Optional callback: Callback

      The callback that handles the response. If omit, the response will be handled via Promise

    Returns Command

Properties

args: CommandParameter[]
ignore?: boolean
inTransaction: boolean = false
isReadOnly?: boolean
isResolved: boolean = false
isSettled: boolean = false
isTraced: boolean = false
name: string

Command name

pipelineIndex?: number
promise: Promise<any>
reject: ((err) => void)

Type declaration

    • (err): void
    • Parameters

      • err: Error

      Returns void

resolve: ((result) => void)

Type declaration

    • (result): void
    • Parameters

      • result: any

      Returns void

FLAGS: {
    BLOCKING_COMMANDS: ["blpop", "brpop", "brpoplpush", "blmove", "blmovem", "bzpopmin", "bzpopmax", "bzmpop", "blmpop", "xread", "xreadgroup"];
    BLOCK_OPTION_COMMANDS: ["xread", "xreadgroup"];
    ENTER_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "ssubscribe"];
    EXIT_SUBSCRIBER_MODE: ["unsubscribe", "punsubscribe", "sunsubscribe"];
    FIRST_ARG_TIMEOUT_COMMANDS: ["bzmpop", "blmpop"];
    HANDSHAKE_COMMANDS: ["auth", "hello", "select", "client", "readonly", "info"];
    IGNORE_RECONNECT_ON_ERROR: ["client"];
    LAST_ARG_TIMEOUT_COMMANDS: ["blpop", "brpop", "brpoplpush", "blmove", "bzpopmin", "bzpopmax"];
    VALID_IN_MONITOR_MODE: ["monitor", "auth"];
    VALID_IN_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "unsubscribe", "punsubscribe", "ssubscribe", "sunsubscribe", "ping", "quit"];
    WILL_DISCONNECT: ["quit"];
} = ...

Type declaration

  • BLOCKING_COMMANDS: ["blpop", "brpop", "brpoplpush", "blmove", "blmovem", "bzpopmin", "bzpopmax", "bzmpop", "blmpop", "xread", "xreadgroup"]
  • BLOCK_OPTION_COMMANDS: ["xread", "xreadgroup"]
  • ENTER_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "ssubscribe"]
  • EXIT_SUBSCRIBER_MODE: ["unsubscribe", "punsubscribe", "sunsubscribe"]
  • FIRST_ARG_TIMEOUT_COMMANDS: ["bzmpop", "blmpop"]
  • HANDSHAKE_COMMANDS: ["auth", "hello", "select", "client", "readonly", "info"]
  • IGNORE_RECONNECT_ON_ERROR: ["client"]
  • LAST_ARG_TIMEOUT_COMMANDS: ["blpop", "brpop", "brpoplpush", "blmove", "bzpopmin", "bzpopmax"]
  • VALID_IN_MONITOR_MODE: ["monitor", "auth"]
  • VALID_IN_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "unsubscribe", "punsubscribe", "ssubscribe", "sunsubscribe", "ping", "quit"]
  • WILL_DISCONNECT: ["quit"]

Methods

  • Extract the blocking timeout from the command arguments.

    Returns number

    The timeout in seconds, null for indefinite blocking (timeout of 0), or undefined if this is not a blocking command

  • Returns (string | Buffer)[]

  • Set a timeout for blocking commands. When the timeout expires, the command resolves with null (matching Redis behavior). This handles the case of undetectable network failures (e.g., docker network disconnect) where the TCP connection becomes a zombie and no close event fires.

    Parameters

    • ms: number

    Returns void

  • Parameters

    • context: ReplyContext

    Returns void

  • Set the wait time before terminating the attempt to execute a command and generating an error.

    Parameters

    • ms: number

    Returns void

  • Convert command to writable buffer or string

    Parameters

    • _socket: object

    Returns string | Buffer

  • Convert buffer/buffer[] to string/string[], and apply reply transformer.

    Parameters

    • result: Buffer | Buffer[]

    Returns string | string[] | Buffer | Buffer[]

  • Check whether the command has the flag

    Type Parameters

    • T extends keyof CommandNameFlags

    Parameters

    • flagName: T
    • commandName: string

    Returns commandName is CommandNameFlags[T][number]

  • Parameters

    • name: string
    • func: ArgumentTransformer

    Returns void

  • Parameters

    • name: string
    • func: ReplyTransformer

    Returns void