mirror of
https://github.com/redis/go-redis.git
synced 2026-10-28 08:24:54 +08:00
Tests that skip when Redis is absent gated on a client Ping to a hardcoded/helper address. A Ping to an addr with nothing listening does not fail fast: it pays the dial-retry (DialerRetries, default 5) plus command-retry budget first, ~1.7s per call. A recent RE integration nightly spent ~1.6 min across 68 such skips. Probe the address with a short-timeout TCP dial first, which fails in microseconds on connection-refused, then keep the existing Ping so a reachable-but-unusable server still skips rather than proceeds.
19 lines
489 B
Go
19 lines
489 B
Go
package redis
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// probeRedis is the package redis copy of the redis_test helper of the same
|
|
// name (the internal tests cannot import the external test package). See
|
|
// probe_test.go for the rationale: a fast TCP probe avoids the ~1.7s
|
|
// dial-retry + command-retry cost a Ping pays when nothing is listening.
|
|
func probeRedis(addr string) error {
|
|
c, err := net.DialTimeout("tcp", addr, 300*time.Millisecond)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return c.Close()
|
|
}
|