MCPcopy
hub / github.com/redis/ioredis / sendCommand

Method sendCommand

lib/Redis.ts:445–597  ·  view source on GitHub ↗

* Send a command to Redis * * This method is used internally and in most cases you should not * use it directly. If you need to send a command that is not supported * by the library, you can use the `call` method: * * ```js * const redis = new Redis(); * * redis.call('set'

(command: Command, stream?: WriteableStream)

Source from the content-addressed store, hash-verified

443 * @ignore
444 */
445 sendCommand(command: Command, stream?: WriteableStream): unknown {
446 if (this.status === "wait") {
447 this.connect().catch(noop);
448 }
449 if (this.status === "end") {
450 command.reject(new Error(CONNECTION_CLOSED_ERROR_MSG));
451 return command.promise;
452 }
453 if (
454 this.condition?.subscriber &&
455 !Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", command.name)
456 ) {
457 command.reject(
458 new Error(
459 "Connection in subscriber mode, only subscriber commands may be used"
460 )
461 );
462 return command.promise;
463 }
464
465 if (typeof this.options.commandTimeout === "number") {
466 command.setTimeout(this.options.commandTimeout);
467 }
468
469 const blockingTimeout = this.getBlockingTimeoutInMs(command);
470
471 let writable =
472 this.status === "ready" ||
473 (!stream &&
474 this.status === "connect" &&
475 exists(command.name, { caseInsensitive: true }) &&
476 (hasFlag(command.name, "loading", { nameCaseInsensitive: true }) ||
477 Command.checkFlag("HANDSHAKE_COMMANDS", command.name)));
478 if (!this.stream) {
479 writable = false;
480 } else if (!this.stream.writable) {
481 writable = false;
482 // @ts-expect-error
483 } else if (this.stream._writableState && this.stream._writableState.ended) {
484 // TODO: We should be able to remove this as the PR has already been merged.
485 // https://github.com/iojs/io.js/pull/1217
486 writable = false;
487 }
488
489 if (!writable) {
490 if (!this.options.enableOfflineQueue) {
491 command.reject(
492 new Error(
493 "Stream isn't writeable and enableOfflineQueue options is false"
494 )
495 );
496 return command.promise;
497 }
498
499 if (command.name === "quit" && this.offlineQueue.length === 0) {
500 this.disconnect();
501 command.resolve(Buffer.from("OK"));
502 return command.promise;

Callers 2

handleReconnectionMethod · 0.95
executeMethod · 0.45

Calls 15

connectMethod · 0.95
disconnectMethod · 0.95
_getDescriptionMethod · 0.95
setSocketTimeoutMethod · 0.95
_buildCommandContextMethod · 0.95
isIntFunction · 0.90
traceCommandFunction · 0.90
rejectMethod · 0.80
checkFlagMethod · 0.80
setTimeoutMethod · 0.80

Tested by

no test coverage detected