5
我需要給定主機查找到Node.js的相應的IP似乎有這樣兩種本地方法:的Node.js dns.resolve()VS dns.lookup()
> dns.resolve('google.com', (error, addresses) => { console.error(error); console.log(addresses); });
QueryReqWrap {
bindingName: 'queryA',
callback: { [Function: asyncCallback] immediately: true },
hostname: 'google.com',
oncomplete: [Function: onresolve],
domain:
Domain {
domain: null,
_events: { error: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> null
[ '216.58.194.174' ]
和:
> dns.lookup('google.com', (error, address, family) => { console.error(error); console.log(address); console.log(family); });
GetAddrInfoReqWrap {
callback: { [Function: asyncCallback] immediately: true },
family: 0,
hostname: 'google.com',
oncomplete: [Function: onlookup],
domain:
Domain {
domain: null,
_events: { error: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> null
216.58.194.174
4
都返回相同的IPv4地址。 dns.lookup()
和dns.resolve()
有何區別?另外,哪個更適合每秒處理大量請求?
值得一提的是,每次解析的IP地址列表都以不同的順序出現。這可以用於負載平衡(使用循環方法進行DNS解析)。 https://www.nginx.com/resources/glossary/dns-load-balancing/ – rocketspacer