Skip to content

Commit

Permalink
expose setting tcp nodelay on connections
Browse files Browse the repository at this point in the history
  • Loading branch information
stlava committed May 9, 2024
1 parent 9f4b1be commit 31cf616
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions redisconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Opts struct {
// TCPKeepAlive - KeepAlive parameter for net.Dialer
// default is IOTimeout / 3
TCPKeepAlive time.Duration
// TCPNoDelay - Sets TCP_NODELAY when connecting via tcp to server
TCPNoDelay bool
// Handle is returned with Connection.Handle()
Handle interface{}
// WritePause - write loop pauses for this time to collect more requests.
Expand Down Expand Up @@ -589,6 +591,14 @@ func (conn *Connection) dial() error {
KeepAlive: conn.opts.TCPKeepAlive,
}
connection, err = dialer.DialContext(conn.ctx, network, address)

if tcpConn, ok := connection.(*net.TCPConn); ok {
// Configure TCP_NODELAY
if err := tcpConn.SetNoDelay(conn.opts.TCPNoDelay); err != nil {
return conn.errWrap(ErrConnSetup, err)
}
}

if err != nil {
return conn.errWrap(ErrDial, err)
}
Expand Down

0 comments on commit 31cf616

Please sign in to comment.