Merge pull request #60 from bergie/master

Enable connecting to Redis with URL
This commit is contained in:
Anatoliy Chakkaev 2012-04-10 07:38:47 -07:00
commit 73481ac5b9
2 changed files with 17 additions and 2 deletions

View File

@ -8,12 +8,24 @@ var redis = safeRequire('redis');
exports.initialize = function initializeSchema(schema, callback) { exports.initialize = function initializeSchema(schema, callback) {
if (!redis) return; if (!redis) return;
if (schema.settings.url) {
var url = require('url');
var redisUrl = url.parse(schema.settings.url);
var redisAuth = (redisUrl.auth || '').split(':');
schema.settings.host = redisUrl.hostname;
schema.settings.port = redisUrl.port;
if (redisAuth.length == 2) {
schema.settings.db = redisAuth[0];
schema.settings.password = redisAuth[1];
}
}
schema.client = redis.createClient( schema.client = redis.createClient(
schema.settings.port, schema.settings.port,
schema.settings.host, schema.settings.host,
schema.settings.options schema.settings.options
); );
schema.client.auth(schema.settings.password); schema.client.auth(schema.settings.password);
schema.client.on('connect', callback); schema.client.on('connect', callback);
@ -361,7 +373,7 @@ function applyFilter(filter) {
} }
}); });
return pass; return pass;
} };
function test(example, value) { function test(example, value) {
if (typeof value === 'string' && example && example.constructor.name === 'RegExp') { if (typeof value === 'string' && example && example.constructor.name === 'RegExp') {

View File

@ -48,6 +48,9 @@ function Schema(name, settings) {
this.name = name; this.name = name;
this.settings = settings; this.settings = settings;
// Disconnected by default
this.connected = false;
// create blank models pool // create blank models pool
this.models = {}; this.models = {};
this.definitions = {}; this.definitions = {};