MCPcopy
hub / github.com/redis/go-redis / masterReplicaDialer

Function masterReplicaDialer

sentinel.go:579–610  ·  view source on GitHub ↗
(
	failover *sentinelFailover,
)

Source from the content-addressed store, hash-verified

577}
578
579func masterReplicaDialer(
580 failover *sentinelFailover,
581) func(ctx context.Context, network, addr string) (net.Conn, error) {
582 return func(ctx context.Context, network, _ string) (net.Conn, error) {
583 var addr string
584 var err error
585
586 if failover.opt.ReplicaOnly {
587 addr, err = failover.RandomReplicaAddr(ctx)
588 } else {
589 addr, err = failover.MasterAddr(ctx)
590 if err == nil {
591 failover.trySwitchMaster(ctx, addr)
592 }
593 }
594 if err != nil {
595 return nil, err
596 }
597 if failover.opt.Dialer != nil {
598 return failover.opt.Dialer(ctx, network, addr)
599 }
600
601 netDialer := &net.Dialer{
602 Timeout: failover.opt.DialTimeout,
603 KeepAlive: 5 * time.Minute,
604 }
605 if failover.opt.TLSConfig == nil {
606 return netDialer.DialContext(ctx, network, addr)
607 }
608 return tls.DialWithDialer(netDialer, network, addr, failover.opt.TLSConfig)
609 }
610}
611
612//------------------------------------------------------------------------------
613

Callers 1

NewFailoverClientFunction · 0.85

Calls 3

RandomReplicaAddrMethod · 0.80
MasterAddrMethod · 0.80
trySwitchMasterMethod · 0.80

Tested by

no test coverage detected