fix: ssl/tls config lost when connection via ssh (#305)

This commit is contained in:
Lykin
2025-07-19 14:37:11 +08:00
parent dc86fb75c6
commit 0f66a00c66

View File

@@ -196,9 +196,28 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
}
}
if dialer != nil {
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
}
if tlsConfig != nil {
// use dialer with tls config
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
rawConn, err := dial(ctx, network, addr)
if err != nil {
rawConn.Close()
return nil, err
}
tlsConn := tls.Client(rawConn, tlsConfig)
if err = tlsConn.Handshake(); err != nil {
rawConn.Close()
return nil, err
}
return tlsConn, nil
}
} else {
option.Dialer = dial
}
option.ReadTimeout = -2
option.WriteTimeout = -2
}