How to use the redis/lib/commands.forEach function in redis

To help you get started, we’ve selected a few redis 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 mjackson / then-redis / modules / client.js View on Github external
var args = (typeof hash === 'object') ? appendHashToArray(hash, []) : slice.call(arguments, 0);
      return this.send('msetnx', args);
    }
  },

  // Optionally accept a hash as the first argument to HMSET after the key.
  hmset: {
    value: function (key, hash) {
      var args = (typeof hash === 'object') ? appendHashToArray(hash, [ key ]) : slice.call(arguments, 0);
      return this.send('hmset', args);
    }
  }

});

require('redis/lib/commands').forEach(function (command) {
  // Some commands have spaces in them, like CONFIG SET.
  command = command.split(' ')[0];

  if (Client.prototype[command])
    return;

  Object.defineProperty(Client.prototype, command, {
    value: function () {
      return this.send(command, slice.call(arguments, 0));
    }
  });
});

module.exports = Client;
github carlos8f / haredis / index.js View on Github external
this._slaveOk = command;
  }
  else if (command) {
    return (this._slaveOk || this.options.auto_slaveok) && this.isRead(command);
  }
  else {
    this._slaveOk = true;
  }
  return this;
};

commands.forEach(function(k) {
  commands.push(k.toUpperCase());
});

commands.forEach(function(k) {
  RedisHAClient.prototype[k] = function() {
    var args = Array.prototype.slice.call(arguments);
    var self = this;
    k = k.toLowerCase();
    if (k == 'multi') {
      return new HAMulti(this, args[0]);
    }
    if (!this.ready) {
      // @todo: create a custom multi() method which can return a chainable thing
      // instead here.
      this.queue.push([k, args]);
      return;
    }

    var skipOpcounter = false;
    switch (k) {