go-redis/redis · error

redis: no valid results to aggregate for max operation

Error message

redis: no valid results to aggregate for max operation

What it means

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.

Source

Thrown at internal/routing/aggregator.go:16

package routing

import (
	"errors"
	"fmt"
	"math"
	"sync"

	"sync/atomic"

	"github.com/redis/go-redis/v9/internal/util"
	uberAtomic "go.uber.org/atomic"
)

var (
	ErrMaxAggregation = errors.New("redis: no valid results to aggregate for max operation")
	ErrMinAggregation = errors.New("redis: no valid results to aggregate for min operation")
	ErrAndAggregation = errors.New("redis: no valid results to aggregate for logical AND operation")
	ErrOrAggregation  = errors.New("redis: no valid results to aggregate for logical OR operation")
)

// ResponseAggregator defines the interface for aggregating responses from multiple shards.
type ResponseAggregator interface {
	// Add processes a single shard response.
	Add(result interface{}, err error) error

	// AddWithKey processes a single shard response for a specific key (used by keyed aggregators).
	AddWithKey(key string, result interface{}, err error) error

	BatchAdd(map[string]AggregatorResErr) error

	BatchSlice([]AggregatorResErr) error

	// Result returns the final aggregated result and any error.

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Check cluster health — one or more shards may be down (inspect the underlying shard errors).
  2. Ensure the aggregated command actually returns numeric values on every shard.
  3. Verify the command's response policy mapping (agg_max) is correct for the data shape.

Example fix

// before
res, err := clusterClient.SomeMaxAggCmd(ctx)
// after — handle empty/aggregation failure explicitly
res, err := clusterClient.SomeMaxAggCmd(ctx)
if errors.Is(err, routing.ErrMaxAggregation) {
    // no shard had a valid value; degrade gracefully
    return 0, nil
}
Defensive patterns

Strategy: try-catch

Validate before calling

// No app-level pre-check; ensure cluster is healthy and the command maps to agg_max correctly.

Try / catch

res, err := clusterClient.SomeMaxAggCmd(ctx)
if errors.Is(err, routing.ErrMaxAggregation) {
    // no shard contributed a valid value
    return 0, nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Cluster node failures during a fan-out, keys missing on all shards, or a command returning non-numeric results fed into a max aggregator.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/d82c9b85925afe9e.json. Report an issue: GitHub.