go-redis/redis · error

redis: the length of the array must be a multiple of 2, got:

Error message

redis: the length of the array must be a multiple of 2, got: %d

What it means

Error "redis: the length of the array must be a multiple of 2, got: %d" thrown in go-redis/redis.

Source

Thrown at internal/proto/reader.go:766

// If responding to the array type (RespArray/RespSet/RespPush),
// it must be a multiple of 2 and return n/2.
// Other types will return an error.
func (r *Reader) ReadMapLen() (int, error) {
	line, err := r.ReadLine()
	if err != nil {
		return 0, err
	}
	switch line[0] {
	case RespMap:
		return replyLen(line)
	case RespArray, RespSet, RespPush:
		// Some commands and RESP2 protocol may respond to array types.
		n, err := replyLen(line)
		if err != nil {
			return 0, err
		}
		if n%2 != 0 {
			return 0, fmt.Errorf("redis: the length of the array must be a multiple of 2, got: %d", n)
		}
		return n / 2, nil
	default:
		return 0, fmt.Errorf("redis: can't parse map reply: %.100q", line)
	}
}

// DiscardNext read and discard the data represented by the next line.
func (r *Reader) DiscardNext() error {
	line, err := r.readLine()
	if err != nil {
		return err
	}
	return r.Discard(line)
}

// Discard the data represented by line.
func (r *Reader) Discard(line []byte) (err error) {

View on GitHub (pinned to 36d97525cd)

Solutions

  1. The key/value array length must be even; check the server reply or the constructed arguments
  2. Reconnect if the stream is desynchronized

When it happens

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

Common situations: Build key/value lists from pairs so odd lengths are impossible.


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