go-redis/redis · error

redis: got %d elements in slowlog get, expected at least 4

Error message

redis: got %d elements in slowlog get, expected at least 4

What it means

Thrown by SlowLogCmd.readReply (command.go:5702). Each SLOWLOG GET entry must have at least 4 fields (id, timestamp, duration-us, command-args); the parser reads those four unconditionally, so a shorter entry would desync the stream and is rejected.

Source

Thrown at command.go:5702

func (cmd *SlowLogCmd) String() string {
	cmd.await()
	return cmdString(cmd, cmd.val)
}

func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error {
	n, err := rd.ReadArrayLen()
	if err != nil {
		return err
	}
	cmd.val = make([]SlowLog, n)

	for i := 0; i < len(cmd.val); i++ {
		nn, err := rd.ReadArrayLen()
		if err != nil {
			return err
		}
		if nn < 4 {
			return fmt.Errorf("redis: got %d elements in slowlog get, expected at least 4", nn)
		}

		if cmd.val[i].ID, err = rd.ReadInt(); err != nil {
			return err
		}

		createdAt, err := rd.ReadInt()
		if err != nil {
			return err
		}
		cmd.val[i].Time = time.Unix(createdAt, 0)

		costs, err := rd.ReadInt()
		if err != nil {
			return err
		}
		cmd.val[i].Duration = time.Duration(costs) * time.Microsecond

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Verify with `redis-cli SLOWLOG GET 10` that every entry has at least id/time/us/command.
  2. Remove RESP-rewriting proxies from the path.
  3. Upgrade go-redis (the parser tolerates extra trailing fields like the Redis 8.10 total-args field).
  4. Retry if the failure looks transient.
Defensive patterns

Strategy: try-catch

Try / catch

entries, err := client.SlowLogGet(ctx, 128).Result()
if err != nil {
    // slowlog is observability-only; degrade gracefully
    entries = nil
}

Prevention

When it happens

Trigger: client.SlowLogGet(ctx, num) where a slowlog entry array has fewer than 4 elements: a non-conformant Redis fork, a proxy mangling the reply, or a corrupted/truncated RESP frame.

Common situations: Redis-compatible service with a different SLOWLOG shape; transient corruption; pointing at a proxy that rewrites replies.

Related errors


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