diff --git a/lib/connect-redis.js b/lib/connect-redis.js index af7dde11..8d16944a 100644 --- a/lib/connect-redis.js +++ b/lib/connect-redis.js @@ -48,7 +48,26 @@ module.exports = function(connect){ ? 'sess:' : options.prefix; + if (options.url) { + var url = require('url').parse(options.url); + if (url.protocol === 'redis:') { + if (url.auth) { + var userparts = url.auth.split(":"); + options.user = userparts[0]; + if (userparts.length === 2) { + options.pass = userparts[1]; + } + } + options.host = url.hostname; + options.port = url.port; + if (url.pathname) { + options.db = url.pathname.replace("/", "", 1); + } + } + } + this.client = options.client || new require('redis').createClient(options.port || options.socket, options.host, options); + if (options.pass) { this.client.auth(options.pass, function(err){ if (err) throw err; diff --git a/package.json b/package.json index a4c6b984..8e085104 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "connect-redis", "description": "Redis session store for Connect", - "version": "1.4.6", + "version": "1.4.7", "author": "TJ Holowaychuk ", "main": "./index.js", "repository": { "type": "git", "url": "git@github.com:visionmedia/connect-redis.git" }, diff --git a/test.js b/test.js index 8bc40660..f854c01d 100644 --- a/test.js +++ b/test.js @@ -9,6 +9,7 @@ var assert = require('assert') var store = new RedisStore; var store_alt = new RedisStore({ db: 15 }); +var store_url = new RedisStore({ url: "redis://localhost:6379/db2" }); store.client.on('connect', function(){ // #set() @@ -27,6 +28,7 @@ store.client.on('connect', function(){ console.log('done'); store.client.end(); store_alt.client.end(); + store_url.client.end(); process.exit(0); }); });