How to use the redis.Multi 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 salesforce / refocus / cache / redisCache.js View on Github external
*
 * Set up redis client connections.
 */
'use strict'; // eslint-disable-line strict
const redis = require('redis');
const logger = require('../logger');
const rconf = require('../config').redis;
const featureToggles = require('feature-toggles');

/*
 * This will add "...Async" to all node_redis functions (e.g. return
 * client.getAsync().then(...)).
 */
const bluebird = require('bluebird');
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

const opts = {

  /* Redis Client Retry Strategy */
  retry_strategy: (options) => {

    /*
     * Stop retrying if we've exceeded the configured threshold since the last
     * successful connection. Flush all commands with a custom error message.
     */
    if (options.total_retry_time > rconf.retryStrategy.totalRetryTime) {
      return new Error('Retry time exhausted');
    }

    /*
     * Stop retrying if we've already tried the maximum number of configured
github ZhaoTianze / leaderboard-promise / lib / leaderboard.js View on Github external
var redis = require('redis');
var Promise = require('bluebird');

// use bluebird for node-redis add Promise API
Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

/**
 * @param {String} name
 * @param {Object} options
 * @param {Object} redisOptions
 */
function Leaderboard(name,options,redisOptions) {
    options || (options = {});

    this.name = name;
    this.pageSize = options.pageSize || 50;
    this.reverse = options.reverse || false;

    this.connect(redisOptions);
}
github olymp / olymp / src / @old / graphql / store-redis / index.js View on Github external
const shortID = require('shortid');
const bluebird = require('bluebird');
const lodash = require('lodash');
const redis = require('redis');
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
var s = require('searchjs');
const createSessionStore = require('./session');

module.exports = config => {
  if (typeof config === 'string') {
    config = { url: config };
  }

  const client = redis.createClient(config);

  client.on('error', function (err) {
    console.error('Redis error', err)
  });

  const read = (kind, options = {}) => {
    if (options.id) return client.hgetAsync(kind, options.id).then(x => {
github MZMonster / node-thrift-service / lib / redis.js View on Github external
*
 * @author zzxun 
 */
'use strict';

/**
 * module dependencies
 */
const _ = require('lodash');
const redis = require('redis');
const Promises = require('bluebird');
const EventEmitter = require('events').EventEmitter;

const utils = require('./util');
Promises.promisifyAll(redis.RedisClient.prototype);
Promises.promisifyAll(redis.Multi.prototype);

/**
 * for client
 */
class RedisService extends EventEmitter {

  /**
   * redis config of `https://github.com/NodeRedis/node_redis`
   * @param {Object} [options]
   */
  constructor(options) {
    super();

    let self = this;

    self._options = _.merge({
github FreeFeed / freefeed-server / app / support / DbAdapter.js View on Github external
import _ from 'lodash'
import validator from 'validator'
import NodeCache from 'node-cache'
import redis from 'redis'
import cacheManager from 'cache-manager'
import redisStore from 'cache-manager-redis'
import pgFormat from 'pg-format';
import { promisifyAll } from 'bluebird'

import { load as configLoader } from '../../config/config'

import { Attachment, Comment, Group, Post, Timeline, User } from '../models'

promisifyAll(redis.RedisClient.prototype);
promisifyAll(redis.Multi.prototype);

const unexistedUID = '00000000-0000-0000-C000-000000000046';

const USER_COLUMNS = {
  username:               'username',
  screenName:             'screen_name',
  email:                  'email',
  description:            'description',
  type:                   'type',
  profilePictureUuid:     'profile_picture_uuid',
  createdAt:              'created_at',
  updatedAt:              'updated_at',
  directsReadAt:          'directs_read_at',
  isPrivate:              'is_private',
  isProtected:            'is_protected',
  isRestricted:           'is_restricted',
github c3subtitles / L2S2 / server / src / entry.js View on Github external
require('./flowWorkarounds');

global.encrypt = function(value) {
  return new Promise(resolve => {
    bcrypt.genSalt(10, (err, salt) => {
      bcrypt.hash(value, salt, (err, hash) => {
        resolve(hash);
      });
    });
  });
};

bluebird.promisifyAll(RedisSessions.prototype);
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

UUID.create = function(old) {
  return function() {
    const uuid = old.apply(this, arguments);
    return uuid.hex;
  };
}(UUID.create);
if (process.env.NODE_ENV !== 'production') {
  require('pretty-error').start();
}

global.Promise = bluebird;



global.app = new koa();
github calzoneman / sync / src / redis / redisclientprovider.js View on Github external
import clone from 'clone';
import redis from 'redis';
import Promise from 'bluebird';
Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

/**
 * Provider for RedisClients.
 */
class RedisClientProvider {
    /**
     * Create a new RedisClientProvider.
     *
     * @param {Object} redisConfig default configuration to use
     * @see {@link https://www.npmjs.com/package/redis}
     */
    constructor(redisConfig) {
        this.redisConfig = redisConfig;
    }

    /**
github velopert / bitimulate / bitimulate-backend / src / lib / cache.js View on Github external
const redis = require('redis');
const bluebird = require('bluebird');

bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

module.exports = (function() {
  const client = redis.createClient();
  
  return {
    get client() {
      return client;
    },
    set(key, value, exp) {
      if(exp) {
        return client.setAsync(key, JSON.stringify(value), 'EX', exp);
      }
      return client.setAsync(key, JSON.stringify(value));
    },
    get(key) {
      return client.getAsync(key).then(data => {
github nitish24p / microab / lib / redis.js View on Github external
/*

* Redis factory
* initialise Client
*/

const redis = require('redis');
const bluebird = require('bluebird');

bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

exports.configureRedisFactory = function(options) {
  if (!options.hasOwnProperty('redis')) {
    throw new Error('Incorrect redis config object format');
  }
  const socket = options.redis.socket;
  const port = !socket ? options.redis.port || 6379 : null;
  const host = !socket ? options.redis.host || '127.0.0.1' : null;
  const db = !socket ? options.redis.db || 0 : null;
  const client = redis.createClient(
    socket || port,
    host,
    options.redis.options
  );
  if (options.redis.auth) {
    client.auth(options.redis.auth);
github nylas-mail-lives / nylas-mail / packages / cloud-core / pubsub-connector.js View on Github external
const Rx = require('rx-lite')
const redis = require("redis");
const {PromiseUtils} = require('isomorphic-core');

PromiseUtils.promisifyAll(redis.RedisClient.prototype);
PromiseUtils.promisifyAll(redis.Multi.prototype);


class PubsubConnector {
  constructor() {
    this._broadcastClient = null;
    this._listenClient = null;
    this._listenClientSubs = {};
  }

  buildClient(accountId, {onClose} = {}) {
    const client = redis.createClient(process.env.REDIS_URL || null);
    global.Logger.info({account_id: accountId}, "Connecting to Redis")
    client.on("error", (...args) => {
      global.Logger.error(...args);
      if (onClose) onClose();
    });