diff --git a/lib/adapters/redis.js b/lib/adapters/redis.js index b9bcc935..97599240 100644 --- a/lib/adapters/redis.js +++ b/lib/adapters/redis.js @@ -8,12 +8,24 @@ var redis = safeRequire('redis'); exports.initialize = function initializeSchema(schema, callback) { 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.settings.port, schema.settings.host, schema.settings.options ); - schema.client.auth(schema.settings.password); schema.client.on('connect', callback); @@ -361,7 +373,7 @@ function applyFilter(filter) { } }); return pass; - } + }; function test(example, value) { if (typeof value === 'string' && example && example.constructor.name === 'RegExp') { diff --git a/lib/schema.js b/lib/schema.js index da48d496..158a4d21 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -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 = {};