{"record":{"id":"44612df97326b2ea","repo":"thanos-io/thanos","slug":"not-found-key-s-in-results","errorCode":null,"errorMessage":"not found key %s in results","messagePattern":"not found key (.+?) in results","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cortex/chunk/cache/redis_client.go","lineNumber":145,"sourceCode":"}\n\nfunc (c *RedisClient) MGet(ctx context.Context, keys []string) ([][]byte, error) {\n\tvar cancel context.CancelFunc\n\tif c.timeout > 0 {\n\t\tctx, cancel = context.WithTimeout(ctx, c.timeout)\n\t\tdefer cancel()\n\t}\n\n\tret := make([][]byte, 0, len(keys))\n\n\tmgetRet, err := rueidis.MGet(c.rdb, ctx, keys)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, k := range keys {\n\t\tm, ok := mgetRet[k]\n\t\tif !ok {\n\t\t\treturn nil, errors.Errorf(\"not found key %s in results\", k)\n\t\t}\n\t\tif m.IsNil() {\n\t\t\tret = append(ret, nil)\n\t\t\tcontinue\n\t\t}\n\t\tr, err := m.ToString()\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"failed to convert %s resp to string\", k)\n\t\t}\n\t\tret = append(ret, stringToBytes(r))\n\t}\n\n\treturn ret, nil\n}\n\nfunc (c *RedisClient) Close() error {\n\tc.rdb.Close()\n\treturn nil","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/internal/cortex/chunk/cache/redis_client.go#L127-L163","documentation":"RedisClient.MGet builds a reply map from the MGET response and requires every requested key to be present in that map. If a key is missing from the server's reply (protocol mismatch, key eviction race between request build and reply parse) it returns this error naming the key.","triggerScenarios":"Calling MGet(ctx, keys) and the returned rueidis reply map lacks one of the requested keys, so mgetRet[k] lookup fails with ok==false.","commonSituations":"Duplicate keys requested causing reply-map key collisions; proxy/cluster client dropping keys; mismatch between key list sent and reply parsed after a partial failure.","solutions":["Deduplicate the key list before calling MGet — duplicates collapse in the reply map.","Treat the missing key as a cache miss instead: wrap MGet and substitute nil for absent keys.","Check for cluster/proxy behavior that truncates MGET replies and fall back to per-key GETs.","Log the key from the error and verify it was part of the original request batch."],"exampleFix":"// before\nvals, err := client.MGet(ctx, keys)\n// after: dedupe before the call\nuniq := make([]string, 0, len(keys))\nseen := map[string]struct{}{}\nfor _, k := range keys {\n    if _, ok := seen[k]; !ok { seen[k] = struct{}{}; uniq = append(uniq, k) }\n}\nvals, err := client.MGet(ctx, uniq)","handlingStrategy":"fallback","validationCode":"uniq := make([]string, 0, len(keys))\nseen := map[string]struct{}{}\nfor _, k := range keys { if _, ok := seen[k]; !ok { seen[k] = struct{}{}; uniq = append(uniq, k) } }\nkeys = uniq","typeGuard":null,"tryCatchPattern":"vals, err := client.MGet(ctx, keys)\nif err != nil && strings.Contains(err.Error(), \"not found key\") {\n    log.Warnf(\"treating MGet failure as cache miss: %v\", err)\n    vals = nil // fall through to recompute and repopulate\n}","preventionTips":["Deduplicate requested keys before MGet.","Wrap MGet and degrade to cache-miss instead of failing queries.","Use a cluster-aware client in Redis Cluster deployments."],"tags":["redis","mget","cache-miss"],"backgroundTag":"record-not-found","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}