{"id":"78af3fed133fbb86","repo":"go-redis/redis","slug":"redis-got-d-elements-in-geosearch-reply-expecte","errorCode":null,"errorMessage":"redis: got %d elements in GEOSEARCH reply, expected at least %d","messagePattern":"redis: got (.+?) elements in GEOSEARCH reply, expected at least (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":5140,"sourceCode":"\t// parser read into the next reply; extra elements are drained below so a\n\t// longer entry (e.g. from a newer server) can't leave frames on the wire.\n\twithLen := 1\n\tif cmd.opt.WithDist {\n\t\twithLen++\n\t}\n\tif cmd.opt.WithHash {\n\t\twithLen++\n\t}\n\tif cmd.opt.WithCoord {\n\t\twithLen++\n\t}\n\tfor i := 0; i < n; i++ {\n\t\tnn, err := rd.ReadArrayLen()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif nn < withLen {\n\t\t\treturn fmt.Errorf(\"redis: got %d elements in GEOSEARCH reply, expected at least %d\", nn, withLen)\n\t\t}\n\n\t\tvar loc GeoLocation\n\n\t\tloc.Name, err = rd.ReadString()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif cmd.opt.WithDist {\n\t\t\tloc.Dist, err = rd.ReadFloat()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\tif cmd.opt.WithHash {\n\t\t\tloc.GeoHash, err = rd.ReadInt()\n\t\t\tif err != nil {\n\t\t\t\treturn err","sourceCodeStart":5122,"sourceCodeEnd":5158,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/command.go#L5122-L5158","documentation":"Thrown by GeoSearchLocationCmd.readReply (command.go:5140). For each result entry the parser expects at least one element per requested WITH* flag (WITHDist/WITHHash/WITHCoord), since Redis echoes back exactly those fields. If an entry is shorter than the expected minimum the parser aborts to avoid consuming the next entry's bytes.","triggerScenarios":"client.GeoSearchLocation(ctx, key, q) where the GEOSEARCH reply's per-entry array is shorter than the WITH* flags requested. In practice this means a non-conformant server/proxy that drops requested fields, or a corrupted/truncated reply.","commonSituations":"A RESP-rewriting proxy between client and Redis; a Redis fork that returns a different GEOSEARCH shape; rare corruption during heavy load or a flaky connection.","solutions":["Run the equivalent GEOSEARCH ... WITHCOORD WITHDIST WITHHASH in redis-cli and confirm each entry has the requested number of fields.","Remove any proxy that may be trimming the reply, or simplify the query to drop WITH* flags and confirm the error disappears.","Upgrade go-redis; the parser drains extra fields but still enforces the minimum.","If transient, retry on a healthy connection."],"exampleFix":"// before\nq := &redis.GeoSearchLocationQuery{GeoSearchQuery: redis.GeoSearchQuery{...}, Sort: \"ASC\"}\nq.WithCoord = true; q.WithDist = true; q.WithHash = true\nres, err := client.GeoSearchLocation(ctx, \"geo\", q).Result()\n// after: confirm the server really returns the requested fields; if a proxy strips them,\n// bypass the proxy or drop the WITH* flags you don't strictly need.","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := client.GeoSearchLocation(ctx, key, q).Result()\nif err != nil {\n    // optionally retry without WITH* flags to confirm a server/proxy shape issue\n    q.WithCoord, q.WithDist, q.WithHash = false, false, false\n    res, err = client.GeoSearchLocation(ctx, key, q).Result()\n    return res, err\n}","preventionTips":["Run GEOSEARCH with the same WITH* flags in redis-cli to confirm the server returns the expected fields.","Remove RESP-rewriting intermediaries."],"tags":["geo","geosearch","resp-parsing","server-compat"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}