Back to Ioredis

Class Command

docs/classes/Command.html

6.0.07.8 KB
Original Source

Class Command

Command instance

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

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

Implements

  • Respondable

Index

Constructors

constructor

Properties

argsignore?inTransactionisReadOnly?isResolvedisSettledisTracednamepipelineIndex?promiserejectresolveFLAGS

Methods

extractBlockingTimeoutgetKeysgetSlotsetBlockingTimeoutsetReplyContextsetTimeoutstringifyArgumentstoWritabletransformReplycheckFlagsetArgumentTransformersetReplyTransformer

Constructors

constructor

  • new Command(name, args?, options?, callback?): Command

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

args: CommandParameter[]

Optional ignore

ignore?: boolean

inTransaction

inTransaction: boolean = false

Optional isReadOnly

isReadOnly?: boolean

isResolved

isResolved: boolean = false

isSettled

isSettled: boolean = false

isTraced

isTraced: boolean = false

name

name: string

Command name

Optional pipelineIndex

pipelineIndex?: number

promise

promise: Promise<any>

reject

reject: ((err) => void)

Type declaration

    • (err): void

Parameters

- err: Error

Returns void

resolve

resolve: ((result) => void)

Type declaration

    • (result): void

Parameters

- result: any

Returns void

Static FLAGS

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

extractBlockingTimeout

  • extractBlockingTimeout(): number

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

getKeys

  • getKeys(): (string | Buffer)[]

Returns (string | Buffer)[]

getSlot

  • getSlot(): number

Returns number

setBlockingTimeout

  • setBlockingTimeout(ms): void

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

setReplyContext

  • setReplyContext(context): void

Parameters

  • context: ReplyContext

Returns void

setTimeout

  • setTimeout(ms): void

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

Parameters

  • ms: number

Returns void

stringifyArguments

  • stringifyArguments(): void

Returns void

toWritable

  • toWritable(_socket): string | Buffer

Convert command to writable buffer or string

Parameters

  • _socket: object

Returns string | Buffer

transformReply

  • transformReply(result): string | string[] | Buffer | Buffer[]

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

Parameters

  • result: Buffer | Buffer[]

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

Static checkFlag

  • checkFlag<T>(flagName, commandName): commandName is CommandNameFlags[T][number]

Check whether the command has the flag

Type Parameters

  • T extends keyof CommandNameFlags

Parameters

  • flagName: T
  • commandName: string

Returns commandName is CommandNameFlags[T][number]

Static setArgumentTransformer

  • setArgumentTransformer(name, func): void

Parameters

  • name: string
  • func: ArgumentTransformer

Returns void

Static setReplyTransformer

  • setReplyTransformer(name, func): void

Parameters

  • name: string
  • func: ReplyTransformer

Returns void

Settings

Member Visibility

  • Inherited

Theme

OSLightDark

On This Page

constructorargsignoreinTransactionisReadOnlyisResolvedisSettledisTracednamepipelineIndexpromiserejectresolveFLAGSextractBlockingTimeoutgetKeysgetSlotsetBlockingTimeoutsetReplyContextsetTimeoutstringifyArgumentstoWritabletransformReplycheckFlagsetArgumentTransformersetReplyTransformer