diff --git a/pipe.go b/pipe.go index 6125d4a..cf7c298 100644 --- a/pipe.go +++ b/pipe.go @@ -3,6 +3,7 @@ package valkey import ( "bufio" "context" + "crypto/tls" "errors" "fmt" "io" @@ -321,10 +322,19 @@ func (p *pipe) _exit(err error) { p.clhks.Load().(func(error))(err) } +func disableNoDelay(conn net.Conn) { + if c, ok := conn.(*tls.Conn); ok { + conn = c.NetConn() + } + if c, ok := conn.(*net.TCPConn); ok { + c.SetNoDelay(false) + } +} + func (p *pipe) _background() { p.conn.SetDeadline(time.Time{}) - if conn, ok := p.conn.(*net.TCPConn); ok && p.noNoDelay { - conn.SetNoDelay(false) + if p.noNoDelay { + disableNoDelay(p.conn) } go func() { p._exit(p._backgroundWrite()) diff --git a/valkey_test.go b/valkey_test.go index 0b47b94..7df9c49 100644 --- a/valkey_test.go +++ b/valkey_test.go @@ -302,8 +302,9 @@ func TestTLSClient(t *testing.T) { _, port, _ := net.SplitHostPort(ln.Addr().String()) client, err := NewClient(ClientOption{ - InitAddress: []string{"127.0.0.1:" + port}, - TLSConfig: config, + InitAddress: []string{"127.0.0.1:" + port}, + TLSConfig: config, + DisableTCPNoDelay: true, }) if err != nil { t.Fatal(err)