MCPcopy
hub / github.com/redis/node-redis / _executeMulti

Method _executeMulti

packages/client/lib/client/index.ts:1565–1632  ·  view source on GitHub ↗

* @internal

(
    commands: Array<RedisMultiQueuedCommand>,
    selectedDB?: number
  )

Source from the content-addressed store, hash-verified

1563 * @internal
1564 */
1565 async _executeMulti(
1566 commands: Array<RedisMultiQueuedCommand>,
1567 selectedDB?: number
1568 ) {
1569 const dirtyWatch = this._self.#dirtyWatch;
1570 this._self.#dirtyWatch = undefined;
1571 const watchEpoch = this._self.#watchEpoch;
1572 this._self.#watchEpoch = undefined;
1573
1574 if (!this._self.#socket.isOpen) {
1575 throw new ClientClosedError();
1576 }
1577
1578 if (dirtyWatch) {
1579 throw new WatchError(dirtyWatch);
1580 }
1581
1582 if (watchEpoch && watchEpoch !== this._self.socketEpoch) {
1583 throw new WatchError('Client reconnected after WATCH');
1584 }
1585
1586 const batchSize = commands.length;
1587
1588 return trace(CHANNELS.TRACE_BATCH,
1589 async () => {
1590 const typeMapping = this._commandOptions?.typeMapping;
1591 const chainId = Symbol('MULTI Chain');
1592 const promises: Array<Promise<unknown>> = [
1593 this._self.#queue.addCommand(['MULTI'], { chainId }),
1594 ];
1595
1596 for (const { args } of commands) {
1597 promises.push(
1598 this._self.#queue.addCommand(args, {
1599 chainId,
1600 typeMapping
1601 })
1602 );
1603 }
1604
1605 promises.push(
1606 this._self.#queue.addCommand(['EXEC'], { chainId })
1607 );
1608
1609 this._self.#scheduleWrite();
1610
1611 const results = await Promise.all(promises),
1612 execResult = results[results.length - 1];
1613
1614 if (execResult === null) {
1615 throw new WatchError();
1616 }
1617
1618 if (selectedDB !== undefined) {
1619 this._self.#selectedDB = selectedDB;
1620 }
1621
1622 return execResult as Array<unknown>;

Callers 3

execMethod · 0.45
MULTIMethod · 0.45
MULTIMethod · 0.45

Calls 5

traceFunction · 0.90
#scheduleWriteMethod · 0.80
#socketTraceContextMethod · 0.80
addCommandMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected