Skip to content

Commit

Permalink
added db and prefix options
Browse files Browse the repository at this point in the history
  • Loading branch information
weepy@github.com authored and weepy@github.com committed Oct 26, 2010
1 parent 1bfd219 commit e63c6c3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/connect-redis.js
Expand Up @@ -23,6 +23,10 @@ var RedisStore = module.exports = function RedisStore(options) {
options = options || {}; options = options || {};
Store.call(this, options); Store.call(this, options);
this.client = new redis.createClient(options.port, options.host, options); this.client = new redis.createClient(options.port, options.host, options);
this.prefix = options.prefix;
if(options.db != null) {
this.client.select(options.db);
}
}; };


/** /**
Expand All @@ -40,6 +44,9 @@ RedisStore.prototype.__proto__ = Store.prototype;
*/ */


RedisStore.prototype.get = function(hash, fn){ RedisStore.prototype.get = function(hash, fn){
if(this.prefix)
hash = this.prefix + hash;

this.client.get(hash, function(err, data){ this.client.get(hash, function(err, data){
try { try {
fn(null, data fn(null, data
Expand All @@ -61,6 +68,9 @@ RedisStore.prototype.get = function(hash, fn){
*/ */


RedisStore.prototype.set = function(hash, sess, fn){ RedisStore.prototype.set = function(hash, sess, fn){
if(this.prefix)
hash = this.prefix + hash;

var self = this; var self = this;
try { try {
this.client.set(hash, JSON.stringify(sess), function(){ this.client.set(hash, JSON.stringify(sess), function(){
Expand All @@ -80,6 +90,9 @@ RedisStore.prototype.set = function(hash, sess, fn){
*/ */


RedisStore.prototype.destroy = function(hash, fn){ RedisStore.prototype.destroy = function(hash, fn){
if(this.prefix)
hash = this.prefix + hash;

this.client.del(hash, fn); this.client.del(hash, fn);
}; };


Expand Down

0 comments on commit e63c6c3

Please sign in to comment.