go-redis/redis · error

redis: can't peek reply type, no data available

Error message

redis: can't peek reply type, no data available

What it means

Error "redis: can't peek reply type, no data available" thrown in go-redis/redis.

Source

Thrown at internal/pool/conn.go:999

// HasBufferedData safely checks if the connection has buffered data.
// This method is used to avoid data races when checking for push notifications.
func (cn *Conn) HasBufferedData() bool {
	// Use read lock for concurrent access to reader state
	cn.readerMu.RLock()
	defer cn.readerMu.RUnlock()
	return cn.rd.Buffered() > 0
}

// PeekReplyTypeSafe safely peeks at the reply type.
// This method is used to avoid data races when checking for push notifications.
func (cn *Conn) PeekReplyTypeSafe() (byte, error) {
	// Use read lock for concurrent access to reader state
	cn.readerMu.RLock()
	defer cn.readerMu.RUnlock()

	if cn.rd.Buffered() <= 0 {
		return 0, fmt.Errorf("redis: can't peek reply type, no data available")
	}
	return cn.rd.PeekReplyType()
}

// PeekReplyTypeForCheck peeks at the reply type while holding readerMu, so it is
// safe against a concurrent SetNetConn resetting the reader during handoff.
// Unlike PeekReplyTypeSafe it does not require the data to already be buffered:
// the pool health check calls it after connCheck reports unexpected socket data,
// and connCheck only MSG_PEEKs, so the byte still has to be pulled from the
// socket into the reader here.
func (cn *Conn) PeekReplyTypeForCheck() (byte, error) {
	cn.readerMu.RLock()
	defer cn.readerMu.RUnlock()
	return cn.rd.PeekReplyType()
}

func (cn *Conn) Write(b []byte) (int, error) {
	// Lock-free netConn access for better performance

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Ensure the server response has fully arrived before peeking (check read deadlines/buffering)
  2. Do not peek on a connection with no pending reply

When it happens

Trigger: Thrown at internal/pool/conn.go:999 when the library encounters an invalid state.

Common situations: Pair every peek with a preceding write of a command expecting a reply.


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/b62c9bf845239df9.json. Report an issue: GitHub.