Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support to use an existing Redis client connection #14

Closed
wants to merge 1 commit into from

6 participants

@NachoMan

I'm connecting to a remote Redis server on another machine (e.g. not using the default localhost IP/port) and using the connect-redis plugin as-is causes things to fail since it can't connect. This change adds the ability to supply an existing client connection.

@maritz

Just out of curiosity: What exactly is the problem why connect-redis can't connect to the server but another client can?

@NachoMan

If I already have a client connection object created for my object store, why should I have to supply hostname and password credentials in multiple places? Other Node libraries appear to accept an existing client to a property setter, which means I can just create my one client object and can pass that around.

@maritz

Okay, so it's not so much a "cannot use it" but more a "would like to use it more comfortable". Seems good to me. :)

(The reason I'm using up to 3 seperate clients (connect sessions, model storage and other) is that I select different databases with each to keep my stuff seperated.)

@NachoMan

That makes sense. Largely I'd like to consolidate the creation of my database connections so that I don't have hostnames strewn throughout my code. My project hasn't gotten to the point where I need to segregate my databases (I'm sure I'll get there shortly) but having options is always nice.

Thanks.

@thomasfr

oh, i just saw your pull request. Maybe this one solves your problem: #14

@maxrabin

Why hasn't this been merged yet? Any reason not to use a singleton connection object?

@chirag04
Collaborator

as badunk said, you can pass connection object.

@chirag04 chirag04 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 6 deletions.
  1. +13 −6 lib/connect-redis.js
View
19 lib/connect-redis.js
@@ -28,12 +28,19 @@ var oneDay = 86400;
var RedisStore = module.exports = function RedisStore(options) {
options = options || {};
Store.call(this, options);
- this.client = new redis.createClient(options.port, options.host, options);
- if (options.db) {
- var self = this;
- self.client.on('connect', function() {
- self.client.select(options.db);
- });
+ if (options.client) {
+ this.client = options.client;
+ if (options.db) {
+ this.client.select(options.db);
+ }
+ } else {
+ this.client = new redis.createClient(options.port, options.host, options);
+ if (options.db) {
+ var self = this;
+ self.client.on('connect', function() {
+ self.client.select(options.db);
+ });
+ }
}
};
Something went wrong with that request. Please try again.