How to use the cluster-key-slot.generateMulti function in cluster-key-slot

To help you get started, we’ve selected a few cluster-key-slot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github luin / ioredis / lib / pipeline.ts View on Github external
if (!this._queue.length) {
    this.resolve([]);
  }
  let pipelineSlot: number;
  if (this.isCluster) {
    // List of the first key for each command
    const sampleKeys: string[] = [];
    for (let i = 0; i < this._queue.length; i++) {
      var keys = this._queue[i].getKeys();
      if (keys.length) {
        sampleKeys.push(keys[0]);
      }
    }

    if (sampleKeys.length) {
      pipelineSlot = generateMulti(sampleKeys);
      if (pipelineSlot < 0) {
        this.reject(
          new Error("All keys in the pipeline should belong to the same slot")
        );
        return this.promise;
      }
    } else {
      // Send the pipeline to a random node
      pipelineSlot = (Math.random() * 16384) | 0;
    }
  }

  // Check whether scripts exists
  const scripts = [];
  for (let i = 0; i < this._queue.length; ++i) {
    var item = this._queue[i];
github luin / ioredis / lib / pipeline.js View on Github external
if (!this._queue.length) {
    this.resolve([]);
  }
  var pipelineSlot, i;
  if (this.isCluster) {
    // List of the first key for each command
    var sampleKeys = [];
    for (i = 0; i < this._queue.length; i++) {
      var keys = this._queue[i].getKeys();
      if (keys.length) {
        sampleKeys.push(keys[0]);
      }
    }

    if (sampleKeys.length) {
      pipelineSlot = calculateSlot.generateMulti(sampleKeys);
      if (pipelineSlot < 0) {
        this.reject(new Error('All keys in the pipeline should belong to the same slot'));
        return this.promise;
      }
    } else {
      // Send the pipeline to a random node
      pipelineSlot = Math.random() * 16384 | 0;
    }
  }

  // Check whether scripts exists
  var scripts = [];
  for (i = 0; i < this._queue.length; ++i) {
    var item = this._queue[i];
    if (this.isCluster && item.isCustomCommand) {
      this.reject(new Error('Sending custom commands in pipeline is not supported in Cluster mode.'));

cluster-key-slot

Generates CRC hashes for strings - for use by node redis clients to determine key slots.

Apache-2.0
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular cluster-key-slot functions