Skip to content
This repository

Add support to use an existing Redis client connection #14

Closed
wants to merge 1 commit into from

6 participants

Michael Nachbaur Moritz Peters Thomas Fritz Max Rabin Duncan Wong Chirag
Michael Nachbaur

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.

Moritz Peters

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

Michael Nachbaur

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.

Moritz Peters

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.)

Michael Nachbaur

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.

Thomas Fritz

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

Max Rabin

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

Chirag
Collaborator

as badunk said, you can pass connection object.

Chirag chirag04 closed this October 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 05, 2011
Michael Nachbaur Added support for passing a pre-populated redis client connection 222d174
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 13 additions and 6 deletions. Show diff stats Hide diff stats

  1. 19  lib/connect-redis.js
19  lib/connect-redis.js
@@ -28,12 +28,19 @@ var oneDay = 86400;
28 28
 var RedisStore = module.exports = function RedisStore(options) {
29 29
   options = options || {};
30 30
   Store.call(this, options);
31  
-  this.client = new redis.createClient(options.port, options.host, options);
32  
-  if (options.db) {
33  
-    var self = this;
34  
-    self.client.on('connect', function() {
35  
-      self.client.select(options.db);
36  
-    });
  31
+  if (options.client) {
  32
+    this.client = options.client;
  33
+    if (options.db) {
  34
+      this.client.select(options.db);
  35
+    }
  36
+  } else {
  37
+    this.client = new redis.createClient(options.port, options.host, options);
  38
+    if (options.db) {
  39
+      var self = this;
  40
+      self.client.on('connect', function() {
  41
+        self.client.select(options.db);
  42
+      });
  43
+    }
37 44
   }
38 45
 };
39 46
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.