Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
'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
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);