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

Method sendCommand

lib/cluster/index.ts:511–704  ·  view source on GitHub ↗

* @ignore

(command: Command, stream?: WriteableStream, node?: any)

Source from the content-addressed store, hash-verified

509 * @ignore
510 */
511 sendCommand(command: Command, stream?: WriteableStream, node?: any): unknown {
512 if (this.status === "wait") {
513 this.connect().catch(noop);
514 }
515 if (this.status === "end") {
516 command.reject(new Error(CONNECTION_CLOSED_ERROR_MSG));
517 return command.promise;
518 }
519 let to = this.options.scaleReads;
520 if (to !== "master") {
521 const isCommandReadOnly =
522 command.isReadOnly ||
523 (exists(command.name) && hasFlag(command.name, "readonly"));
524 if (!isCommandReadOnly) {
525 to = "master";
526 }
527 }
528
529 let targetSlot = node ? node.slot : command.getSlot();
530 const ttl = {};
531 const _this = this;
532 if (!node && !REJECT_OVERWRITTEN_COMMANDS.has(command)) {
533 REJECT_OVERWRITTEN_COMMANDS.add(command);
534
535 const reject = command.reject;
536 command.reject = function (err) {
537 const partialTry = tryConnection.bind(null, true);
538 _this.handleError(err, ttl, {
539 moved: function (slot, key) {
540 debug("command %s is moved to %s", command.name, key);
541 targetSlot = Number(slot);
542 if (_this.slots[slot]) {
543 _this.slots[slot][0] = key;
544 } else {
545 _this.slots[slot] = [key];
546 }
547 _this._groupsBySlot[slot] =
548 _this._groupsIds[_this.slots[slot].join(";")];
549 _this.connectionPool.findOrCreate(_this.natMapper(key));
550 tryConnection();
551 debug("refreshing slot caches... (triggered by MOVED error)");
552 _this.refreshSlotsCache();
553 },
554 ask: function (slot, key) {
555 debug("command %s is required to ask %s:%s", command.name, key);
556 const mapped = _this.natMapper(key);
557 _this.connectionPool.findOrCreate(mapped);
558 tryConnection(false, `${mapped.host}:${mapped.port}`);
559 },
560 tryagain: partialTry,
561 clusterDown: partialTry,
562 connectionClosed: partialTry,
563 maxRedirections: function (redirectionError) {
564 reject.call(command, redirectionError);
565 },
566 defaults: function () {
567 reject.call(command, err);
568 },

Callers 3

readyHandlerFunction · 0.45
tryConnectionMethod · 0.45

Calls 9

connectMethod · 0.95
rejectMethod · 0.80
getSlotMethod · 0.80
handleErrorMethod · 0.80
findOrCreateMethod · 0.80
natMapperMethod · 0.80
refreshSlotsCacheMethod · 0.80
callMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected