go-redis/redis · error

redis: no valid results to aggregate for logical AND operati

Error message

redis: no valid results to aggregate for logical AND operation

What it means

routing.ErrAndAggregation is returned by AggLogicalAndAggregator.Result() when no shard contributed a boolean result (aggregator.go:543-545). hasResult stays false unless at least one Add stored a boolean, so an entirely empty/errored fan-out yields this error.

Source

Thrown at internal/routing/aggregator.go:18

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.
	Result() (interface{}, error)
}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Inspect the per-shard errors to find which node(s) failed.
  2. Confirm the command's response policy (agg_logical_and) matches boolean-producing output.
  3. Treat the aggregation-empty case explicitly in the caller (e.g. default to false).

Example fix

// before
res, err := clusterClient.BoolAndCmd(ctx)
// after
res, err := clusterClient.BoolAndCmd(ctx)
if errors.Is(err, routing.ErrAndAggregation) {
    return false, nil // no valid shard results
}
Defensive patterns

Strategy: try-catch

Validate before calling

// No app-level pre-check; ensure all shards healthy and command returns booleans.

Try / catch

res, err := clusterClient.BoolAndCmd(ctx)
if errors.Is(err, routing.ErrAndAggregation) {
    return false, nil
}

Prevention

When it happens

Trigger: A ClusterClient command using RespAggLogicalAnd where every shard errored or none returned a boolean, so the AND has no operands.

Common situations: Cluster-wide failures, all shards returning errors, or a command mis-mapped to agg_logical_and when its results aren't boolean.

Related errors


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