go-redis/redis · error

redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >

Error message

redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >= 0

What it means

Returned by AutoPipelineOptions.Validate when MaxConcurrentBatches is negative. Zero is allowed (treated as the default, 1); negative values are rejected as typos. Note this is the lower-bound check — a separate check (error 74) governs values > 1 without Unordered.

Source

Thrown at autopipeline.go:231

// Options.AutoPipelineOptions is validated lazily — on the first getter
// call, not in NewClient.
func (cfg *AutoPipelineOptions) Validate() error {
	if cfg.MaxConcurrentBatches > 1 && !cfg.Unordered {
		return fmt.Errorf("redis: AutoPipelineOptions.MaxConcurrentBatches=%d requires Unordered:true "+
			"(parallel batches do not preserve command ordering); set Unordered:true to allow it, "+
			"or keep MaxConcurrentBatches=1 for an ordered stream", cfg.MaxConcurrentBatches)
	}
	// Reject obviously-wrong negatives so a typo surfaces at construction rather
	// than being silently coerced to a default. Zero is allowed and means "use
	// the default" (MaxBatchSize) or "no delay" (MaxFlushDelay).
	if cfg.MaxBatchSize < 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.MaxBatchSize=%d must be >= 0", cfg.MaxBatchSize)
	}
	if cfg.MaxBatchBytes < 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0", cfg.MaxBatchBytes)
	}
	if cfg.MaxConcurrentBatches < 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >= 0", cfg.MaxConcurrentBatches)
	}
	if cfg.MaxFlushDelay < 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0", cfg.MaxFlushDelay)
	}
	if cfg.NumShards < 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.NumShards=%d must be >= 0", cfg.NumShards)
	}
	if cfg.AdaptiveDelay && cfg.MaxFlushDelay <= 0 {
		return fmt.Errorf("redis: AutoPipelineOptions.AdaptiveDelay requires MaxFlushDelay > 0 " +
			"(adaptive delay scales MaxFlushDelay by queue fill; with no MaxFlushDelay it would " +
			"silently disable batch accumulation entirely)")
	}
	return nil
}

// cmdableClient is an interface for clients that support pipelining.
// Both Client and ClusterClient implement this interface. It embeds
// UniversalClient (Cmdable + Process + Do + AddHook + Watch + Subscribe... +

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Set MaxConcurrentBatches to 0 (default of 1) or a non-negative integer.
  2. Use 0 instead of a negative for 'default'.
  3. Validate at config load time.

Example fix

// before
cfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: -1}
// cfg.Validate() => error

// after
cfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: 0} // default (1)
// or, if >1, also set Unordered: true
cfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: 4, Unordered: true}
Defensive patterns

Strategy: validation

Validate before calling

func sanitizeConcurrentBatches(n int) int {
    if n < 0 {
        return 0 // default (1) instead of an invalid negative
    }
    return n
}

Try / catch

if err := cfg.Validate(); err != nil {
    if strings.Contains(err.Error(), "MaxConcurrentBatches") && !strings.Contains(err.Error(), "Unordered") {
        cfg.MaxConcurrentBatches = 0 // reset to default
    }
}

Prevention

When it happens

Trigger: Setting AutoPipelineOptions.MaxConcurrentBatches to a negative number. Config deserialization producing a negative from a missing/invalid field.

Common situations: Config parsing bugs. Sign errors. Treating -1 as 'auto' when zero is the documented 'use default' value.

Related errors


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