Skip to content

Commit 46a1540

Browse files
Introduce -nameserver option to allow to specify the DNS server (#24)
1 parent 51555d8 commit 46a1540

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

redis-bechmark-go.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func main() {
153153
verbose := flag.Bool("verbose", false, "Output verbose info")
154154
continueonerror := flag.Bool("continue-on-error", false, "Output verbose info")
155155
resp := flag.String("resp", "", "redis command response protocol (2 - RESP 2, 3 - RESP 3). If empty will not enforce it.")
156+
nameserver := flag.String("nameserver", "", "the IP address of the DNS name server. The IP address can be an IPv4 or an IPv6 address. If empty will use the default host namserver.")
156157
flag.Var(&benchmarkCommands, "cmd", "Specify a query to send in quotes. Each command that you specify is run with its ratio. For example:-cmd=\"SET __key__ __value__\" -cmd-ratio=1")
157158
flag.Var(&benchmarkCommandsRatios, "cmd-ratio", "The query ratio vs other queries used in the same benchmark. Each command that you specify is run with its ratio. For example: -cmd=\"SET __key__ __value__\" -cmd-ratio=0.8 -cmd=\"GET __key__\" -cmd-ratio=0.2")
158159

@@ -220,7 +221,27 @@ func main() {
220221
} else if *resp == "3" {
221222
opts.Protocol = "3"
222223
}
223-
ips, _ := net.LookupIP(*host)
224+
225+
ips := make([]net.IP, 0)
226+
if *nameserver != "" {
227+
fmt.Printf("Using %s to resolve hostname %s\n", *nameserver, *host)
228+
r := &net.Resolver{
229+
PreferGo: true,
230+
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
231+
d := net.Dialer{
232+
Timeout: time.Millisecond * time.Duration(10000),
233+
}
234+
return d.DialContext(ctx, network, *nameserver)
235+
},
236+
}
237+
ips, _ = r.LookupIP(context.Background(), "ip", *host)
238+
} else {
239+
ips, _ = net.LookupIP(*host)
240+
}
241+
if len(ips) < 1 {
242+
log.Fatalf("Failed to resolve %s to any IP", *host)
243+
}
244+
224245
fmt.Printf("IPs %v\n", ips)
225246

226247
stopChan := make(chan struct{})

0 commit comments

Comments
 (0)