How to use the redis-commands.exists function in redis-commands

To help you get started, we’ve selected a few redis-commands 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 / cluster / index.ts View on Github external
sendCommand(command, stream, node) {
    if (this.status === "wait") {
      this.connect().catch(noop);
    }
    if (this.status === "end") {
      command.reject(new Error(CONNECTION_CLOSED_ERROR_MSG));
      return command.promise;
    }
    let to = this.options.scaleReads;
    if (to !== "master") {
      const isCommandReadOnly =
        commands.exists(command.name) &&
        commands.hasFlag(command.name, "readonly");
      if (!isCommandReadOnly) {
        to = "master";
      }
    }

    let targetSlot = node ? node.slot : command.getSlot();
    const ttl = {};
    const _this = this;
    if (!node && !command.__is_reject_overwritten) {
      // eslint-disable-next-line @typescript-eslint/camelcase
      command.__is_reject_overwritten = true;
      const reject = command.reject;
      command.reject = function(err) {
        const partialTry = tryConnection.bind(null, true);
        _this.handleError(err, ttl, {
github luin / ioredis / lib / redis / index.ts View on Github external
this.condition.subscriber &&
    !Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", command.name)
  ) {
    command.reject(
      new Error(
        "Connection in subscriber mode, only subscriber commands may be used"
      )
    );
    return command.promise;
  }

  var writable =
    this.status === "ready" ||
    (!stream &&
      this.status === "connect" &&
      commands.exists(command.name) &&
      commands.hasFlag(command.name, "loading"));
  if (!this.stream) {
    writable = false;
  } else if (!this.stream.writable) {
    writable = false;
  } else if (this.stream._writableState && this.stream._writableState.ended) {
    // https://github.com/iojs/io.js/pull/1217
    writable = false;
  }

  if (!writable && !this.options.enableOfflineQueue) {
    command.reject(
      new Error(
        "Stream isn't writeable and enableOfflineQueue options is false"
      )
    );
github luin / ioredis / lib / command.ts View on Github external
private _iterateKeys(
    transform: Function = key => key
  ): Array {
    if (typeof this.keys === "undefined") {
      this.keys = [];
      if (commands.exists(this.name)) {
        const keyIndexes = commands.getKeyIndexes(this.name, this.args);
        for (const index of keyIndexes) {
          this.args[index] = transform(this.args[index]);
          this.keys.push(this.args[index] as string | Buffer);
        }
      }
    }
    return this.keys;
  }
github luin / ioredis / lib / command.js View on Github external
Command.prototype._iterateKeys = function (transform) {
  if (typeof this._keys === 'undefined') {
    if (typeof transform !== 'function') {
      transform = function (key) {
        return key;
      };
    }
    this._keys = [];
    if (commands.exists(this.name)) {
      var keyIndexes = commands.getKeyIndexes(this.name, this.args);
      for (var i = 0; i < keyIndexes.length; i++) {
        var index = keyIndexes[i];
        this.args[index] = transform(this.args[index]);
        this._keys.push(this.args[index]);
      }
    }
  }
  return this._keys;
};