Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a default port for sentinel connections. #441

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ var redis = new Redis({

## Sentinel
ioredis supports Sentinel out of the box. It works transparently as all features that work when
you connect to a single node also work when you connect to a sentinel group. Make sure to run Redis >= 2.8.12 if you want to use this feature.
you connect to a single node also work when you connect to a sentinel group. Make sure to run Redis >= 2.8.12 if you want to use this feature. Sentinels have a default port of 26379.

To connect using Sentinel, use:

Expand Down
4 changes: 2 additions & 2 deletions lib/connectors/sentinel_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ SentinelConnector.prototype.resolve = function (endpoint, callback) {
Redis = require('../redis');
}
var client = new Redis({
port: endpoint.port,
port: endpoint.port || 26379,
host: endpoint.host,
retryStrategy: null,
enableReadyCheck: false,
Expand All @@ -232,7 +232,7 @@ function noop() {}

function isSentinelEql(a, b) {
return ((a.host || '127.0.0.1') === (b.host || '127.0.0.1')) &&
((a.port || 6379) === (b.port || 6379));
((a.port || 26379) === (b.port || 26379));
}

module.exports = SentinelConnector;
16 changes: 16 additions & 0 deletions test/functional/sentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ describe('sentinel', function () {

});

it('should default to the default sentinel port', function (done) {
var sentinel = new MockServer(26379);
sentinel.once('connect', function () {
redis.disconnect();
sentinel.disconnect(done);
});

var redis = new Redis({
sentinels: [
{ host: '127.0.0.1' }
],
name: 'master'
});

});

it('should try to connect to all sentinel', function (done) {
var sentinel = new MockServer(27380);
sentinel.once('connect', function () {
Expand Down