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

Conversation

reconbot
Copy link
Contributor

Also add a few helpful notes to the README. This came from some frustrations I had the first time I setup a project to talk to sentinels.

README.md Outdated

To connect using Sentinel, use:

```javascript
var redis = new Redis({
sentinels: [{ host: 'localhost', port: 26379 }, { host: 'localhost', port: 26380 }],
name: 'mymaster'
name: 'mymaster',
db: 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db defaults to 0 so why we add it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a new user to sentinels and not finding any docs for it in the api.md having this clue would have saved me a bit of headache.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db option is not sentinel-specified and it's documented here: https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options. What problem did you encounter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand that fact. I thought sentinels overrode it. I was coming from a project that used urls.

this.sentinels = this.options.sentinels.map(function (endpoint) {
endpoint.port = endpoint.port || 26379;
return endpoint;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating properties of the option introducing side effects. For example:

const sentinels: [{host: '192.168.1.3'}]
const redis = new Redis({sentinels})

console.log(sentinels) // values changed unexpectedly

What about give the default port when creating a new instance by port: endpoint.port || 26379: https://github.com/luin/ioredis/blob/master/lib/connectors/sentinel_connector.js#L213.

There's an isSentinelEql function should be updated accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could copy the sentinel objects, but I get your point. I'll patch.

@reconbot reconbot force-pushed the sentinel-default-ports branch from 0ca44bd to 44a8967 Compare March 20, 2017 16:26
@reconbot
Copy link
Contributor Author

Updated the PR from the review notes.

@luin
Copy link
Collaborator

luin commented Mar 21, 2017

Thank you for the pull request! All look good to me except the db: 0 part. I'm afraid setting it explicitly will lead people into thinking db is required even if they just want to connect to the first database.

Also add a few helpful notes to the README
@reconbot reconbot force-pushed the sentinel-default-ports branch from 44a8967 to b78e692 Compare March 21, 2017 17:40
@reconbot
Copy link
Contributor Author

Alrighty - I'd rather put // optional but I'm not strong on it. Updated PR!

@luin luin merged commit 539fe41 into redis:master Mar 21, 2017
@luin
Copy link
Collaborator

luin commented Mar 21, 2017

Aha! Merged! 🍻

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants