Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: support customize dns lookup function #723

Merged
merged 6 commits into from
Oct 17, 2018
Merged

Conversation

luin
Copy link
Collaborator

@luin luin commented Oct 15, 2018

Since Redis cluster doesn't support hostname at all (redis/redis#2410),
it's reasonable to resolve the hostnames to IPs before connecting.

Since Redis cluster doesn't support hostname at all (redis/redis#2410),
it's reasonable to resolve the hostnames to IPs before connecting.
@luin luin requested a review from AVVS October 15, 2018 18:17
@@ -117,59 +129,68 @@ class Cluster extends EventEmitter {
reject(new Error('Redis is already connecting/connected'))
return
}
const epoch = ++this.connectionEpoch
Copy link
Collaborator

Choose a reason for hiding this comment

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

can overflow (unlikely, but still)

https://github.com/fastify/fastify/blob/master/lib/logger.js#L32-L38 is an example of quick capping of the int so it runs in circles

Copy link

Choose a reason for hiding this comment

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

@@ -108,5 +128,6 @@ export const DEFAULT_CLUSTER_OPTIONS: IClusterOptions = {
retryDelayOnClusterDown: 100,
retryDelayOnTryAgain: 100,
slotsRefreshTimeout: 1000,
slotsRefreshInterval: 5000
slotsRefreshInterval: 5000,
dnsLookup: lookup
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe wrap it as a promise here via util.promisify (I dont remember when it became available) or just as a

dnslookup(hostname: string): Promise<string> => {
  return new Promise((resolve, reject) => {
    lookup(hostname, (err, address) => {
          if (err) {
            debug('failed to resolve hostname %s to IP: %s', hostname, err.message)
            reject(err)
          } else {
            debug('resolved hostname %s to IP %s', hostname, address)
            resolve(address)
          }
        })
  });
},

Copy link
Collaborator

Choose a reason for hiding this comment

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

and then the code would be cleaner in the actual resolve function

@luin luin merged commit b9c4793 into master Oct 17, 2018
ioredis-robot pushed a commit that referenced this pull request Oct 17, 2018
# [4.2.0](v4.1.0...v4.2.0) (2018-10-17)

### Features

* support customize dns lookup function ([#723](#723)) ([b9c4793](b9c4793)), closes [redis/redis#2410](redis/redis#2410)
@ioredis-robot
Copy link
Collaborator

🎉 This PR is included in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@luin luin deleted the cluster/dns-lookup branch October 17, 2018 12:01
@luin
Copy link
Collaborator Author

luin commented Oct 17, 2018

4.2.0 is released with the "latest" tag instead of "next". Besides that, everything works like a charm. @AVVS

@AVVS
Copy link
Collaborator

AVVS commented Oct 17, 2018

need to make sure that .npmrc is present and I've configured it correctly (ie maybe dist-tag=next) is a wrong way to set it :) but yeah, pretty cool 👍

@boltzjf
Copy link

boltzjf commented Dec 10, 2018

Has it been included in Redis 5.0?

@luin
Copy link
Collaborator Author

luin commented Dec 10, 2018

@boltzjf It has nothing to do with Redis 5.0. It has been included in ioredis v4.2.0.

janus-dev87 added a commit to janus-dev87/ioredis-work that referenced this pull request Mar 1, 2024
# [4.2.0](redis/ioredis@v4.1.0...v4.2.0) (2018-10-17)

### Features

* support customize dns lookup function ([#723](redis/ioredis#723)) ([b9c4793](redis/ioredis@b9c4793)), closes [redis/redis#2410](redis/redis#2410)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants