Skip to content

Commit

Permalink
fix interaction with latest node_redis
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessharp committed Nov 20, 2014
1 parent 1161cbf commit 1488efa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ Sentinel.prototype.createClient = function(masterName, opts) {
return client.emit('error', err);
}

client.port = port;
client.host = host;
client.stream.connect(port, host);
var connectionOption = {
port: port,
host: host
};
client.connectionOption = connectionOption;
client.stream.connect(connectionOption.port, connectionOption.host);

// Hijack the emit method so that we can get in there and
// do any reconnection on errors, before raising it up the
Expand All @@ -67,8 +70,8 @@ Sentinel.prototype.createClient = function(masterName, opts) {
resolver(self.endpoints, masterName, function(_err, ip, port) {
if (_err) { oldEmit.call(client, 'error', _err); }
// Try and reconnect
client.port = port;
client.host = ip;
client.connectionOption.port = port;
client.connectionOption.host = ip;
});
}

Expand Down
36 changes: 18 additions & 18 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Redis Sentinel tests', function() {
var endpoints = [{ host: '127.0.0.1', port: 26380}];
var redisClient = sentinel.createClient(endpoints, 'mymaster');
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("6379");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("6379");
done();
});
});
Expand All @@ -20,8 +20,8 @@ describe('Redis Sentinel tests', function() {
var endpoints = [{ host: '127.0.0.1', port: 26380}];
var redisClient = sentinel.createClient(endpoints, 'mymaster', {role:'slave'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.port);
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.connectionOption.port);
done();
});
});
Expand All @@ -30,8 +30,8 @@ describe('Redis Sentinel tests', function() {
var endpoints = [{ host: '127.0.0.1', port: 26380}];
var redisClient = sentinel.createClient(endpoints, {role:'sentinel'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("26380");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("26380");
done();
});
});
Expand All @@ -43,8 +43,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints);
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("6379");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("6379");
done();
});
});
Expand All @@ -56,8 +56,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints, 'mymaster', {role:'slave'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.port);
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.connectionOption.port);
done();
});
});
Expand All @@ -69,8 +69,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints, {role: 'sentinel'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("26380");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("26380");
done();
});
});
Expand All @@ -84,8 +84,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints, 'mymaster');
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("6379");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("6379");
done();
});
});
Expand All @@ -98,8 +98,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints, 'mymaster', {role:'slave'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.port);
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(["6381", "6380"]).to.contain(redisClient.connectionOption.port);
done();
});
});
Expand All @@ -112,8 +112,8 @@ describe('Redis Sentinel tests', function() {
];
var redisClient = sentinel.createClient(endpoints, {role: 'sentinel'});
redisClient.on('ready', function() {
expect(redisClient.host).to.equal('127.0.0.1');
expect(redisClient.port).to.equal("26380");
expect(redisClient.connectionOption.host).to.equal('127.0.0.1');
expect(redisClient.connectionOption.port).to.equal("26380");
done();
});
});
Expand Down

0 comments on commit 1488efa

Please sign in to comment.