Skip to content

Commit

Permalink
mod; for redis 0.12.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wavded committed Aug 29, 2014
1 parent 68ad0d0 commit 41e1090
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
14 changes: 11 additions & 3 deletions lib/connect-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

var debug = require('debug')('connect:redis');
var redis = require('redis');
var default_port = 6379;
var default_host = '127.0.0.1';

/**
* One day in seconds.
Expand Down Expand Up @@ -75,22 +77,28 @@ module.exports = function(session){
this.client = redis.createClient(options.socket, options)
}
else if (options.port || options.host) {
this.client = redis.createClient(options.port, options.host, options)
this.client = redis.createClient(
options.port || default_port,
options.host || default_host,
options
)
}
else {
this.client = redis.createClient(options)
}
// 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;
});
});
}

this.ttl = options.ttl;

if (options.db) {
if (typeof options.db !== 'number')
console.error('Warning: connect-redis expects a number for the "db" option')

self.client.select(options.db);
self.client.on("connect", function() {
self.client.send_anyways = true;
Expand Down
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
"version": "2.0.0",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"main": "./index.js",
"repository": { "type": "git", "url": "git@github.com:visionmedia/connect-redis.git" },
"dependencies": { "redis": "0.12.x", "debug": "*" },
"devDependencies": { "express-session": "*" },
"engines": { "node": "*" },
"repository": {
"type": "git",
"url": "git@github.com:visionmedia/connect-redis.git"
},
"dependencies": {
"debug": "^1.0.4",
"express-session": "^1.7.6",
"redis": "^0.12.1"
},
"devDependencies": {
"express-session": "*"
},
"engines": {
"node": "*"
},
"bugs": {
"url": "https://github.com/visionmedia/connect-redis/issues"
},
"scripts":{
"test":"node test.js"
"scripts": {
"test": "node test.js"
}
}
4 changes: 1 addition & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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()
Expand All @@ -28,7 +27,6 @@ store.client.on('connect', function(){
console.log('done');
store.client.end();
store_alt.client.end();
store_url.client.end();
process.exit(0);
});
});
Expand All @@ -39,4 +37,4 @@ store.client.on('connect', function(){

process.once('uncaughtException', function (err) {
assert.ok(err.message === 'Error in fn', '#get() catch wrong error');
});
});

0 comments on commit 41e1090

Please sign in to comment.