How to use the redis-commands.list 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 moaxaca / async-redis / src / index.js View on Github external
/* eslint func-names: ["error", "as-needed"] */

const redis = require('redis');
const commands = require('redis-commands').list;
const objectDecorator = require('./object-decorator');

const AsyncRedis = function (args) {
  const client = Array.isArray(args) ? redis.createClient(...args) : redis.createClient(args);
  return AsyncRedis.decorate(client);
};

AsyncRedis.createClient = (...args) => new AsyncRedis(args);

// this is the set of commands to NOT promisify
const commandsToSkipSet = new Set(['multi']);
// this is the set of commands to promisify
const commandSet = new Set(commands.filter(c => !commandsToSkipSet.has(c)));

AsyncRedis.decorate = redisClient => objectDecorator(redisClient, (name, method) => {
  if (commandSet.has(name)) {
github NodeRedis / node_redis / lib / commands.js View on Github external
this.queue.push(new Command(command, arr, callback));
            return this;
        };
        // Alias special function names (e.g. NR.RUN becomes NR_RUN and nr_run)
        if (commandName !== command) {
            Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command];
        }
        if (changeFunctionName) {
            Object.defineProperty(Multi.prototype[command], 'name', {
                value: commandName
            });
        }
    }
};

commands.list.forEach(addCommand);

module.exports = addCommand;
github moaxaca / async-redis / test / integration / decorate-redis.spec.js View on Github external
it('should have decorated every command', async () => {
    const commands = redisCommands.list;
    commands.forEach(command => {
      assert.isFunction(asyncRedisClient[command], `redis.${command} isn't decorated`);
    });
  });
});
github microsoft / redie / index.js View on Github external
function getCommands() {
  var commands = {};
  for (var i = 0; i < redisCommands.list.length; i++) {
    commands[redisCommands.list[i].toUpperCase()] = client.send_command.bind(client);
  }
  commands[''] = noopCommand;
  commands.HELP = helpCommand;
  commands.NOOP = noopCommand;
  commands.EXIT = quitCommand;
  commands.QUIT = quitCommand;
  commands.SAVE = saveCommand;
  return commands;
}
github apache / openwhisk-composer / conductor.js View on Github external
function createRedisClient (p) {
    const client = require('redis').createClient(p.s.redis.uri, p.s.redis.ca ? { tls: { ca: Buffer.from(p.s.redis.ca, 'base64').toString('binary') } } : {})
    const noop = () => { }
    let handler = noop
    client.on('error', error => handler(error))
    require('redis-commands').list.forEach(f => {
      client[`${f}Async`] = function () {
        let failed = false
        return new Promise((resolve, reject) => {
          handler = error => {
            handler = noop
            failed = true
            reject(error)
          }
          client[f](...arguments, (error, result) => {
            handler = noop
            return error ? reject(error) : resolve(result)
          })
        }).catch(error => {
          if (failed) client.end(true)
          return Promise.reject(error)
        })
github sagiegurari / multiple-redis / lib / multiple-redis.js View on Github external
function setupPrototype() {
    var commands = redisCommands.list;

    commands.forEach(function addCommandToPrototype(command) {
        MultiRedisClient.prototype[command] = createCommandFunction(command);

        MultiRedisClient.prototype[command.toUpperCase()] = MultiRedisClient.prototype[command];
    });
}
github maxbrieiev / promise-redis / index.js View on Github external
'use strict';

var redis = require('redis'),
    redisCmds = require('redis-commands').list;

function createCb(resolve, reject) {
    return function (err, value) {
        if (err !== null) {
            reject(err);
        } else {
            resolve(value);
        }
    };
}

module.exports = function (promiseFactory) {
    var mlproto = redis.Multi.prototype,
        clproto = redis.RedisClient.prototype;

    if (!promiseFactory) {
github jbaudanza / rxeventstore / src / database / redis_connections.js View on Github external
function createClient() {
      return promisify(driver.createClient(url), without(redisCommands.list, 'multi'));
    }