Some safeties to URL handling

This commit is contained in:
Henri Bergius 2012-04-10 16:30:55 +02:00
parent 24e051b1e9
commit d7cc8b2d51
2 changed files with 9 additions and 4 deletions

View File

@ -11,11 +11,14 @@ exports.initialize = function initializeSchema(schema, callback) {
if (schema.settings.url) {
var url = require('url');
var redisUrl = url.parse(schema.settings.url);
var redisAuth = redisUrl.auth.split(':');
var redisAuth = (redisUrl.auth || '').split(':');
schema.settings.host = redisUrl.hostname;
schema.settings.port = redisUrl.port;
schema.settings.db = redisAuth[0];
schema.settings.password = redisAuth[1];
if (redisAuth.length == 2) {
schema.settings.db = redisAuth[0];
schema.settings.password = redisAuth[1];
}
}
schema.client = redis.createClient(
@ -23,7 +26,6 @@ exports.initialize = function initializeSchema(schema, callback) {
schema.settings.host,
schema.settings.options
);
schema.client.auth(schema.settings.password);
schema.client.on('connect', callback);

View File

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