{"id":"d82c9b85925afe9e","repo":"go-redis/redis","slug":"redis-no-valid-results-to-aggregate-for-max-opera","errorCode":null,"errorMessage":"redis: no valid results to aggregate for max operation","messagePattern":"redis: no valid results to aggregate for max operation","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/routing/aggregator.go","lineNumber":16,"sourceCode":"package routing\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"math\"\n\t\"sync\"\n\n\t\"sync/atomic\"\n\n\t\"github.com/redis/go-redis/v9/internal/util\"\n\tuberAtomic \"go.uber.org/atomic\"\n)\n\nvar (\n\tErrMaxAggregation = errors.New(\"redis: no valid results to aggregate for max operation\")\n\tErrMinAggregation = errors.New(\"redis: no valid results to aggregate for min operation\")\n\tErrAndAggregation = errors.New(\"redis: no valid results to aggregate for logical AND operation\")\n\tErrOrAggregation  = errors.New(\"redis: no valid results to aggregate for logical OR operation\")\n)\n\n// ResponseAggregator defines the interface for aggregating responses from multiple shards.\ntype ResponseAggregator interface {\n\t// Add processes a single shard response.\n\tAdd(result interface{}, err error) error\n\n\t// AddWithKey processes a single shard response for a specific key (used by keyed aggregators).\n\tAddWithKey(key string, result interface{}, err error) error\n\n\tBatchAdd(map[string]AggregatorResErr) error\n\n\tBatchSlice([]AggregatorResErr) error\n\n\t// Result returns the final aggregated result and any error.","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/internal/routing/aggregator.go#L1-L34","documentation":"routing.ErrMaxAggregation is returned by AggMaxAggregator.Result() when no shard contributed a valid integer result (aggregator.go:459-462). The max aggregator only has a value once at least one Add produced an int64; if every shard errored or none were added, hasVal is false and Result fails.","triggerScenarios":"A ClusterClient running a multi-shard command whose response policy is RespAggMax (e.g. a max-aggregating custom/aggregate command) where all shards returned errors or no shard returned a usable integer.","commonSituations":"Cluster node failures during a fan-out, keys missing on all shards, or a command returning non-numeric results fed into a max aggregator.","solutions":["Check cluster health — one or more shards may be down (inspect the underlying shard errors).","Ensure the aggregated command actually returns numeric values on every shard.","Verify the command's response policy mapping (agg_max) is correct for the data shape."],"exampleFix":"// before\nres, err := clusterClient.SomeMaxAggCmd(ctx)\n// after — handle empty/aggregation failure explicitly\nres, err := clusterClient.SomeMaxAggCmd(ctx)\nif errors.Is(err, routing.ErrMaxAggregation) {\n    // no shard had a valid value; degrade gracefully\n    return 0, nil\n}","handlingStrategy":"try-catch","validationCode":"// No app-level pre-check; ensure cluster is healthy and the command maps to agg_max correctly.","typeGuard":null,"tryCatchPattern":"res, err := clusterClient.SomeMaxAggCmd(ctx)\nif errors.Is(err, routing.ErrMaxAggregation) {\n    // no shard contributed a valid value\n    return 0, nil\n}","preventionTips":["Monitor cluster node health; a downed shard fans out as errors.","Verify response policy agg_max matches a numeric-returning command.","Handle the empty-aggregation case explicitly in callers."],"tags":["cluster","routing","aggregation","max","fan-out"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}