Closed cheeaun closed 11 years ago
Good point, care to make a pull request?
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:
createClient
returns data on which node is being used, so that the correct auth can be used for it.auth
method accepts an array of passwords, in the same order as the array passed to createClient
.What do you think?
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.
nice :)
The code seems to assume that all redis instances use the same auth. For my (unique?) case, it's not the same.