Permalink
Browse files

added db and prefix options

  • Loading branch information...
1 parent 1bfd219 commit e63c6c335c20b7761a07faaf58a659d4de348758 weepy@github.com committed Oct 26, 2010
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/connect-redis.js
View
@@ -23,6 +23,10 @@ var RedisStore = module.exports = function RedisStore(options) {
options = options || {};
Store.call(this, options);
this.client = new redis.createClient(options.port, options.host, options);
+ this.prefix = options.prefix;
+ if(options.db != null) {
+ this.client.select(options.db);
+ }
};
/**
@@ -40,6 +44,9 @@ RedisStore.prototype.__proto__ = Store.prototype;
*/
RedisStore.prototype.get = function(hash, fn){
+ if(this.prefix)
+ hash = this.prefix + hash;
+
this.client.get(hash, function(err, data){
try {
fn(null, data
@@ -61,6 +68,9 @@ RedisStore.prototype.get = function(hash, fn){
*/
RedisStore.prototype.set = function(hash, sess, fn){
+ if(this.prefix)
+ hash = this.prefix + hash;
+
var self = this;
try {
this.client.set(hash, JSON.stringify(sess), function(){
@@ -80,6 +90,9 @@ RedisStore.prototype.set = function(hash, sess, fn){
*/
RedisStore.prototype.destroy = function(hash, fn){
+ if(this.prefix)
+ hash = this.prefix + hash;
+
this.client.del(hash, fn);
};

0 comments on commit e63c6c3

Please sign in to comment.