<commit_before>import Command from "./command";
import { deprecate } from "util";
import asCallback from "standard-as-callback";
import { exists, hasFlag } from "redis-commands";
import * as calculateSlot from "cluster-key-slot";
import * as pMap from "p-map";
import * as PromiseContainer from "./promiseContainer";
import { CallbackFunction } from "./types";
import Commander from "./commander";

/*
  This function derives from the cluster-key-slot implementation.
  Instead of checking that all keys have the same slot, it checks that all slots are served by the same set of nodes.
  If this is satisfied, it returns the first key's slot.
*/
function generateMultiWithNodes(redis, keys) {
  const slot = calculateSlot(keys[0]);
  const target = redis.slots[slot].join(",");

  for (let i = 1; i < keys.length; i++) {
    const currentTarget = redis.slots[calculateSlot(keys[i])].join(",");

    if (currentTarget !== target) {
      return -1;
    }
  }

  return slot;
}

export default function Pipeline(redis) {
  Commander.call(this);

  this.redis = redis;
  this.isCluster = this.redis.constructor.name === "Cluster";
  this.isPipeline = true;
  this.options = redis.options;
  this._queue = [];
  this._result = [];
  this._transactions = 0;
  this._shaToScript = {};

  Object.keys(redis.scriptsSet).forEach((name) => {
    const script = redis.scriptsSet[name];
    this._shaToScript[script.sha] = script;
    this[name] = redis[name];
    this[name + "Buffer"] = redis[name + "Buffer"];
  });
<commit_msg>fix(cluster): issues when code is processed by babel (#1298)<commit_after>import Command from "./command";
import { deprecate } from "util";
import asCallback from "standard-as-callback";
import { exists, hasFlag } from "redis-commands";
import * as calculateSlot from "cluster-key-slot";
import * as pMap from "p-map";
import * as PromiseContainer from "./promiseContainer";
import { CallbackFunction } from "./types";
import Commander from "./commander";

/*
  This function derives from the cluster-key-slot implementation.
  Instead of checking that all keys have the same slot, it checks that all slots are served by the same set of nodes.
  If this is satisfied, it returns the first key's slot.
*/
function generateMultiWithNodes(redis, keys) {
  const slot = calculateSlot(keys[0]);
  const target = redis.slots[slot].join(",");

  for (let i = 1; i < keys.length; i++) {
    const currentTarget = redis.slots[calculateSlot(keys[i])].join(",");

    if (currentTarget !== target) {
      return -1;
    }
  }

  return slot;
}

export default function Pipeline(redis) {
  Commander.call(this);

  this.redis = redis;
  this.isCluster =
    this.redis.constructor.name === "Cluster" || this.redis.isCluster;
  this.isPipeline = true;
  this.options = redis.options;
  this._queue = [];
  this._result = [];
  this._transactions = 0;
  this._shaToScript = {};

  Object.keys(redis.scriptsSet).forEach((name) => {
    const script = redis.scriptsSet[name];
    this._shaToScript[script.sha] = script;
    this[name] = redis[name];
    this[name + "Buffer"] = redis[name + "Buffer"];
  });

{'fraction_non_alphanumeric': 0.14005782203662062, 'fraction_numerical': 0.0038548024413748794, 'mean_word_length': 3.9350237717908083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7008844', 'n_tokens_mistral': 974, 'n_tokens_neox': 955, 'n_words': 283}