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

Separate auth for separate redis nodes #4

Merged
merged 1 commit into from Nov 25, 2012

Conversation

Projects
None yet
2 participants
Contributor

cheeaun commented Nov 24, 2012

The code seems to assume that all redis instances use the same auth. For my (unique?) case, it's not the same.

Owner

carlos8f commented Nov 21, 2012

Good point, care to make a pull request?

Contributor

cheeaun commented Nov 21, 2012

I'm not sure what's the best way to implement this. If I'm not mistaken, createClient returns only one client which could point to any node. The solutions that I could think of are either:

  1. createClient returns data on which node is being used, so that the correct auth can be used for it.
  2. auth method accepts an array of passwords, in the same order as the array passed to createClient.

What do you think?

Owner

carlos8f commented Nov 22, 2012

In reality, the haredis client is actually a composite of lots of node_redis clients, which connect to all the nodes (subscriptions and reads can be load-balanced to slaves). The master node has multiple clients connecting to it, to do opcounter writes, normal writes, and subscriptions.

That said, each node object (lib/node.js) has a (potentially) different auth_pass property:

// Stash auth for connect and reconnect.  Send immediately if already connected.
RedisHAClient.prototype.auth = RedisHAClient.prototype.AUTH = function () {
  var args = Array.prototype.slice.call(arguments);
  var self = this;
  this.auth_callback = args[1];
  this.nodes.forEach(function(node) {
    node.auth_pass = args[0];
  });
};

if args[0] is an object, maybe something like:

{
  '1.2.3.4:5678': 'some pass',
  '2.3.4.5:6789': 'some other pass'
}

Then we could parse host/port combos and assign each node a different pass.

Owner

carlos8f commented Nov 25, 2012

nice :)

carlos8f pushed a commit that referenced this pull request Nov 25, 2012

Merge pull request #4 from cheeaun/master
Separate auth for separate redis nodes

@carlos8f carlos8f merged commit 607a4bd into carlos8f:master Nov 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment