How to use the ioredis.Promise function in ioredis

To help you get started, we’ve selected a few ioredis 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 redibox / core / src / core.js View on Github external
this._clientCount = 0;
    this._allClientCount = 0;
    this.bootedAtTimestamp = Date.now();
    this.options = mergeDeep(defaults(), options);
    this.log = createLogger(this.options.log);
    this.options.redis.cluster = !!this.options.redis.hosts && this.options.redis.hosts.length > 0;

    // setup connection timeout
    const connectionFailedTimer = setTimeout(() => {
      const error = new Error('Failed to connect to redis, please check your config / servers.');
      this.handleError(error);
      callback(error);
    }, this.options.redis.connectionTimeout);

    // https://github.com/luin/ioredis#error-handling
    Redis.Promise.onPossiblyUnhandledRejection(this.handleError);

    this.once(this.toEventName('client:default:ready'), () => {
      clearTimeout(connectionFailedTimer);
      // create a ref to default client for niceness
      this.client = this.clients.default;
      hookLoader(this)
        .then(() => {
          this.trumpWall();
          this.emit('ready');
          this.notifyHooks();
          callback();
        }, this.handleError).catch(this.handleError);
    });

    this.createClient('default');
    process.once('SIGTERM', this.quit);
github an-sh / chat-service / src / RedisState.js View on Github external
'use strict'

const Buffer = require('safe-buffer').Buffer
const ChatServiceError = require('./ChatServiceError')
const Promise = require('bluebird')
const Redis = require('ioredis')
const Room = require('./Room')
const User = require('./User')
const _ = require('lodash')
const promiseRetry = require('promise-retry')
const uid = require('uid-safe')
const { mixin } = require('./utils')

Redis.Promise = require('bluebird')

const namespace = 'chatservice'

function initSet (redis, set, values) {
  return redis.del(set)
    .then(() => values ? redis.sadd(set, values) : null)
}

// State init/remove operations.
class StateOperations {
  constructor (name, exitsErrorName, redis, makeKeyName, stateReset) {
    this.name = name
    this.exitsErrorName = exitsErrorName
    this.redis = redis
    this.makeKeyName = makeKeyName
    this.stateReset = stateReset
github origen-chat / api / projects / api / src / core / redis / redis.ts View on Github external
import BluebirdPromise from 'bluebird';
import Redis from 'ioredis';

import logger from '../logger';
import { createRedisClient, waitForRedisClientToBeReady } from './helpers';

// @ts-ignore
Redis.Promise = BluebirdPromise;

// eslint-disable-next-line import/no-mutable-exports
export let redisClient: Redis.Redis;

export async function startRedis(): Promise {
  if (redisClient) {
    return;
  }

  redisClient = createRedisClient();

  logger.info('🎒 cache store (Redis) connection initialized');

  handleRedisClientEvents();

  await waitForRedisClientToBeReady(redisClient);

ioredis

A robust, performance-focused and full-featured Redis client for Node.js.

MIT
Latest version published 2 days ago

Package Health Score

93 / 100
Full package analysis