go-redis/redis · error

expected digit or CRLF, got %q

Error message

expected digit or CRLF, got %q

What it means

Error "expected digit or CRLF, got %q" thrown in go-redis/redis.

Source

Thrown at internal/proto/reader.go:271

	for i := pos; i < len(buf)-1; i++ {
		if buf[i] == '\r' && buf[i+1] == '\n' {
			return util.BytesToString(buf[pos:i]), true, nil
		}
	}
	return "", false, nil
}

// skipDigitsThenCRLF advances past zero-or-more ASCII digits and the
// terminating "\r\n" starting at offset start in buf. It returns the position
// after the "\r\n" and true on success; (pos, false, nil) if buf is too
// short; or an error if a non-digit non-CR byte is encountered before the CRLF.
func skipDigitsThenCRLF(buf []byte, start int) (int, bool, error) {
	for pos := start; pos < len(buf)-1; pos++ {
		if buf[pos] == '\r' && buf[pos+1] == '\n' {
			return pos + 2, true, nil
		}
		if buf[pos] < '0' || buf[pos] > '9' {
			return pos, false, fmt.Errorf("expected digit or CRLF, got %q", buf[pos])
		}
	}
	return len(buf), false, nil
}

// ReadLine Return a valid reply, it will check the protocol or redis error,
// and discard the attribute type.
func (r *Reader) ReadLine() ([]byte, error) {
	line, err := r.readLine()
	if err != nil {
		return nil, err
	}
	switch line[0] {
	case RespError:
		return nil, ParseErrorReply(line)
	case RespNil:
		return nil, Nil
	case RespBlobError:

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Reconnect to resynchronize; the stream contained an unexpected byte where a digit/CRLF was expected
  2. Check for non-Redis traffic on the connection

When it happens

Trigger: Thrown at internal/proto/reader.go:271 when the library encounters an invalid state.

Common situations: Validate every frame strictly and drop the connection on the first malformed byte.


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