Manager.prototype.createClient = function () { var self = this; var host = this.options.host || 'localhost'; var port = this.options.port || 6379; var options = this.options.options || {}; check(port).isInt(); var client = new redis.createClient(port, host, options); if (typeof options.auth == 'string') { client.auth(options.auth); } client.on('error', function (err) { console.log('[' + self.id + '] ' + err); }); client.on('ready', function () { console.log('[' + self.id + '] connected to redis!'); self.emit('ready'); self.retried = 0; }); client.on('end', function () { self.emit('end'); console.log('[' + self.id + '] disconnected from redis'); }); return client; };
constructor(options = {}) { const { port, host, client, setex, password, database, prefix } = options; if ('string' === typeof options) { options = parse(options); } if ('function' === typeof setex) { this.client = options; } else if (client) { this.client = client; } else if (!port && !host) { this.client = new redis.createClient(); } else { this.client = new redis.createClient(port, host, { ...options, prefix: null }); } if (password) { this.client.auth(password, err => { if (err) throw err; }); } if (database) { this.client.select(database, err => { if (err) throw err; }); } this.prefix = prefix || 'cacheman:'; }
var rtg = require('url').parse(process.env.REDISCLOUD_URL); redisConfig = { host: rtg.hostname, port: rtg.port, pass: rtg.auth.split(':')[1] } } else { redisConfig = { host: '127.0.0.1', port: '6379' }; } var redisClient = new redis.createClient(redisConfig.port, redisConfig.host, redisConfig); if (redisConfig.pass) { redisClient.auth(redisConfig.pass, function(err){ if (err) throw err; }); } nconf.set('redis:config',redisConfig); Reap["redisClient"] = redisClient; var allowCrossDomain = function(req, res, next) { if (!_.isUndefined(req) && !_.isUndefined(req.headers) && _.isString(req.headers.origin)) { res.header('Access-Control-Allow-Origin', req.headers.origin); } else { res.header('Access-Control-Allow-Origin', 'http://localhost'); } res.header('Access-Control-Allow-Credentials', 'true'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
var Config = require('Local/Config'); var redis = require('redis'); var client = new redis.createClient(Config.redis.port, Config.redis.host, Config.redis); if (Config.redis.password) { client.auth(Config.redis.password, function(err){ if (err) { throw err; } }); } module.exports = client;