go-redis/redis · error
redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0
Error message
redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0
What it means
Returned by AutoPipelineOptions.Validate when MaxBatchBytes is negative. Zero is allowed (meaning no byte cap); negative values are rejected as configuration errors. MaxBatchBytes caps a batch by approximate payload volume to avoid huge single writes.
Source
Thrown at autopipeline.go:228
// Validate()==nil does not guarantee construction succeeds: rules that need
// the face (e.g. NumShards>1 requires Unordered on the deferred face) are
// enforced by the AutoPipeline/AsyncAutoPipeline getters. Note also that
// 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
}
View on GitHub (pinned to 36d97525cd)
Solutions
- Set MaxBatchBytes to 0 (no byte cap, the default) or a positive byte limit.
- Use 0 rather than a negative for 'disabled'.
- Sanitize config values before constructing the options.
Example fix
// before
cfg := &redis.AutoPipelineOptions{MaxBatchBytes: -1024}
// cfg.Validate() => error
// after
cfg := &redis.AutoPipelineOptions{MaxBatchBytes: 0} // no cap
// or
cfg := &redis.AutoPipelineOptions{MaxBatchBytes: 1 << 20} // 1 MiB cap Defensive patterns
Strategy: validation
Validate before calling
func sanitizeBatchBytes(n int) int {
if n < 0 {
return 0 // no byte cap instead of an invalid negative
}
return n
} Try / catch
if err := cfg.Validate(); err != nil {
if strings.Contains(err.Error(), "MaxBatchBytes") {
cfg.MaxBatchBytes = 0 // reset to no-cap
}
} Prevention
- Use 0 for 'no byte cap' MaxBatchBytes, never a negative.
- Sanitize config values to >= 0 at load time.
- Document 0 as the disabled sentinel in your config schema.
When it happens
Trigger: Setting AutoPipelineOptions.MaxBatchBytes to a negative value. Sign errors or uninitialized config fields producing negatives.
Common situations: Config parsing mistakes. Using a negative sentinel to mean 'disabled' when zero is the documented disabled value. Arithmetic underflow.
Related errors
- redis: AutoPipelineOptions.MaxBatchSize=%d must be >= 0
- redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >
- redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0
- redis: AutoPipelineOptions.NumShards=%d must be >= 0
- redis: AutoPipelineOptions.MaxConcurrentBatches=%d requires
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/33dc8ec2aa9822a2.json.
Report an issue: GitHub.