Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

added db option and prefix #9

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+13 −0
Split
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);
};