{"id":"8823105c94b871ab","repo":"go-redis/redis","slug":"got-d-elements-in-cluster-info-address-expected","errorCode":null,"errorMessage":"got %d elements in cluster info address, expected 2, 3, or 4","messagePattern":"got (.+?) elements in cluster info address, expected 2, 3, or 4","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":4710,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tend, err := rd.ReadInt()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// subtract start and end.\n\t\tnodes := make([]ClusterNode, n-2)\n\n\t\tfor j := 0; j < len(nodes); j++ {\n\t\t\tnn, err := rd.ReadArrayLen()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif nn < 2 || nn > 4 {\n\t\t\t\treturn fmt.Errorf(\"got %d elements in cluster info address, expected 2, 3, or 4\", n)\n\t\t\t}\n\n\t\t\tip, err := rd.ReadString()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tport, err := rd.ReadString()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tnodes[j].Addr = net.JoinHostPort(ip, port)\n\n\t\t\tif nn >= 3 {\n\t\t\t\tid, err := rd.ReadString()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err","sourceCodeStart":4692,"sourceCodeEnd":4728,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/command.go#L4692-L4728","documentation":"Thrown by ClusterSlotsCmd.readReply (command.go:4710) when a per-node address sub-array inside a CLUSTER SLOTS entry does not have 2, 3, or 4 elements (ip/port, optional node-id, optional hostname). The parser must know the exact shape to consume the array correctly, so any other length aborts parsing. Note: the format verb prints `n` (the outer entry length) rather than the sub-array length `nn` due to a long-standing bug in the format arguments, so the reported number can be misleading.","triggerScenarios":"client.ClusterSlots(ctx) where a node-address sub-array is malformed: a non-standard Redis fork, a proxy rewriting CLUSTER SLOTS, or a corrupted/partial RESP frame.","commonSituations":"Using a Redis-compatible proxy or service that emits address arrays of an unexpected length; transient corruption during network instability or failover.","solutions":["Inspect raw CLUSTER SLOTS output with redis-cli and confirm every node tuple is [ip, port] or [ip, port, id] or [ip, port, id, hostname].","Remove any RESP-rewriting proxy from the data path, or switch to a standalone Client if the target is not a real cluster.","Upgrade go-redis for stricter/tolerant parsing and CLUSTER SHARDS support.","Retry once if the error appears during a failover/reshard window."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm CLUSTER SLOTS node tuples are well-formed before relying on them.\nraw, err := client.ClusterSlots(ctx).Result()\nif err != nil { return err }\nfor _, s := range raw {\n    for _, n := range s.Nodes {\n        if n.Addr == \"\" { return fmt.Errorf(\"malformed cluster node address\") }\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := client.ClusterSlots(ctx).Result(); err != nil {\n    // retry after topology settles, or fall back to CLUSTER SHARDS / ReloadState\n    _ = client.ReloadState(ctx)\n    return err\n}","preventionTips":["Bypass proxies that rewrite CLUSTER SLOTS.","Handle the error; the reported number may be the outer entry length, not the address-array length."],"tags":["cluster","cluster-slots","resp-parsing","server-compat"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}