go-redis/redis · error

redis: invalid reply: %q

Error message

redis: invalid reply: %q

What it means

Error "redis: invalid reply: %q" thrown in go-redis/redis.

Source

Thrown at internal/proto/reader.go:333

	b, err := r.rd.ReadSlice('\n')
	if err != nil {
		if err != bufio.ErrBufferFull {
			return nil, err
		}

		full := make([]byte, len(b))
		copy(full, b)

		b, err = r.rd.ReadBytes('\n')
		if err != nil {
			return nil, err
		}

		full = append(full, b...) //nolint:makezero
		b = full
	}
	if len(b) <= 2 || b[len(b)-1] != '\n' || b[len(b)-2] != '\r' {
		return nil, fmt.Errorf("redis: invalid reply: %q", b)
	}
	return b[:len(b)-2], nil
}

func (r *Reader) ReadReply() (interface{}, error) {
	line, err := r.ReadLine()
	if err != nil {
		return nil, err
	}

	switch line[0] {
	case RespStatus:
		return string(line[1:]), nil
	case RespInt:
		return util.ParseInt(line[1:], 10, 64)
	case RespFloat:
		return r.readFloat(line)
	case RespBool:

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Inspect the quoted line in the error; it shows what the server sent instead of a valid reply
  2. Ensure the command sent matches server capabilities

When it happens

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

Common situations: Log the raw offending line (already included) and reconnect on invalid replies.


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