{"record":{"id":"297c27fc9804db53","repo":"redis/go-redis","slug":"redis-got-d-elements-in-latency-get-expected-at","errorCode":null,"errorMessage":"redis: got %d elements in latency get, expected at least 4","messagePattern":"redis: got (.+?) elements in latency get, expected at least 4","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":5855,"sourceCode":"\nfunc (cmd *LatencyCmd) String() string {\n\tcmd.await()\n\treturn cmdString(cmd, cmd.val)\n}\n\nfunc (cmd *LatencyCmd) readReply(rd *proto.Reader) error {\n\tn, err := rd.ReadArrayLen()\n\tif err != nil {\n\t\treturn err\n\t}\n\tcmd.val = make([]Latency, n)\n\tfor i := 0; i < len(cmd.val); i++ {\n\t\tnn, err := rd.ReadArrayLen()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif nn < 4 {\n\t\t\treturn fmt.Errorf(\"redis: got %d elements in latency get, expected at least 4\", nn)\n\t\t}\n\t\tif cmd.val[i].Name, err = rd.ReadString(); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcreatedAt, err := rd.ReadInt()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i].Time = time.Unix(createdAt, 0)\n\t\tlatest, err := rd.ReadInt()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i].Latest = time.Duration(latest) * time.Millisecond\n\t\tmaximum, err := rd.ReadInt()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":5837,"sourceCodeEnd":5873,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L5837-L5873","documentation":"This error comes from the reply parser for `LATENCY HISTORY`/`LATENCY LATEST` (LatencyCmd.readReply in command.go). The Redis docs require each latency event entry to be an array of at least 4 elements (name, timestamp, latest latency, all-time max latency). When the server returns a sub-array with fewer than 4 elements, go-redis refuses to parse it rather than index out of range, indicating either a non-standard/incompatible server or a corrupted/truncated reply.","triggerScenarios":"Calling `client.Latency(ctx, \"HISTORY\", \"event\")` or `Latency(ctx, \"LATEST\", ...)` when the server replies with per-event arrays of fewer than 4 elements — e.g. a proxy/RESP translator, a Redis-compatible server (KeyDB, Dragonfly, Twemproxy) with a divergent LATENCY implementation, or a mocked/stubbed reply with the wrong shape.","commonSituations":"Pointing the client at a Redis-alternative or intermediate proxy that partially implements the LATENCY command; running a very old or non-standard server where LATENCY HISTORY returns 3-tuple entries; unit-test mocks returning simplified arrays.","solutions":["Verify you are connecting to a real Redis server (run `INFO server` and check `redis_version`) rather than a proxy or Redis-compatible alternative.","Upgrade the server to a recent Redis version that implements the full 4-field latency event format (name, timestamp, ms latest, ms all-time).","If a proxy must be used, check whether it strips or rewrites LATENCY replies; either fix the proxy or disable latency monitoring against it.","Capture the actual raw reply (e.g. with `redis-cli --raw LATENCY HISTORY <event>`) to confirm the shape the server sends before filing a bug."],"exampleFix":"// before: mock reply with wrong arity for LATENCY HISTORY\nmock.ExpectLatencyHistory([][]interface{}{{\"event\", 1700000000, 12}})\n\n// after: each event entry must have >= 4 elements (name, ts, latest, max)\nmock.ExpectLatencyHistory([][]interface{}{{\"event\", 1700000000, 12, 40}})","handlingStrategy":"try-catch","validationCode":"// confirm server identity/capability before calling LATENCY\ninfo, err := rdb.Info(ctx, \"server\").Result()\nif err != nil || !strings.Contains(info, \"redis_version:\") {\n    // not a standard Redis: skip latency monitoring\n}","typeGuard":null,"tryCatchPattern":"res, err := rdb.Latency(ctx, \"HISTORY\", event)\nif err != nil {\n    if strings.Contains(err.Error(), \"elements in latency get\") {\n        // non-standard server reply: fall back to manual redis-cli/telemetry\n        return nil, fmt.Errorf(\"latency history unavailable on this server: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Only enable latency monitoring against genuine Redis servers, not proxies or Redis-alternatives.","Pin the server version in your environments and test LATENCY commands against it in CI.","Gate LATENCY usage on `INFO server` capability checks.","Keep go-redis updated so parsers match current Redis reply formats."],"tags":["redis","protocol-parse","latency-command","server-compatibility"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}