Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added db option and prefix #9

Closed
wants to merge 1 commit into from

7 participants

@weepy

makes it easier handling > 1 app per redis instance

@tj
Owner
tj commented

you can use "select" to use a different db

@maritz

+1 vote for prefix

@tj
Owner
tj commented

you really want potentially hundreds of thousands of keys mixed in with your others? :p

@maritz

What's the downside of supporting prefixes for those who need it?

@tj
Owner
tj commented

no downside really, its just that you misewell "select" another db, thats what it is for. We could add an option for that

@weepy

well the point of the prefix is so that you are sure you dont run into your other data that you are saving. You could have a different db just for your sessions, but perhaps it's nicer to have them in the same one ? -- also there's only 16 total dbs in redis

@tj
Owner
tj commented

yeah... but 16 is quite a few, I think it is wayyyyy cleaner to just use a db

@bminer

16 databases is really not that many (especially if you are hosting many virtual hosts)... but no worries... Redis can now be configured to increase the number of databases. I agree with TJ... much cleaner to select another DB than to use prefixes. Although I must say it... wouldn't it be better for the databases to have names, not integers?

@tj
Owner
tj commented

I saw rumour that SELECT and friends are deprecated, not 100% on that

@mking

+1 for prefix.

it looks like Salvatore wants select to go away.

@bminer

These are rumors, guys. SELECT is probably staying for a long, long time. A lot of people would disagree with me, but prefixing keys is not the way to go. It increases the string length of every key in the database... much overhead... what a waste! Unfortunately, Redis doesn't have much in the "key namespacing" department, other than the SELECT command (which is a primitive way of selecting a database - integers, really? I feel like I'm programming on an 8080). Why can't Redis work like MySQL and allow people to create named databases? Who knows?! But for now, I still think SELECT is the best we have.

@chirag04
Collaborator

db and prefix both are present now. closing.

@chirag04 chirag04 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 26, 2010
  1. added db and prefix options

    weepy@github.com authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/connect-redis.js
View
13 lib/connect-redis.js
@@ -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);
};
Something went wrong with that request. Please try again.