go-redis/redis · error
redis: AutoPipelineOptions.NumShards=%d must be >= 0
Error message
redis: AutoPipelineOptions.NumShards=%d must be >= 0
What it means
Returned by AutoPipelineOptions.Validate when NumShards is negative. Zero is allowed (meaning auto: a single shard for standalone, several slot-routed shards for cluster); negative values are rejected. NumShards controls how many independent queue+flusher shards the autopipeliner runs.
Source
Thrown at autopipeline.go:237
"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... +
// Close + PoolStats) so the AutoPipeliner can delegate the non-batched surface
// back to the underlying client and itself satisfy UniversalClient.
type cmdableClient interface {
UniversalClient
// processPipelineHook is the hook-wrapped []Cmder pipeline entry — the same
// method Pipeline.Exec is wired to (see Client.Pipeline). The flusherView on GitHub (pinned to 36d97525cd)
Solutions
- Set NumShards to 0 (auto, the default) or a positive integer.
- Use 0 instead of a negative for 'auto'.
- Validate config values at load time.
Example fix
// before
cfg := &redis.AutoPipelineOptions{NumShards: -1}
// cfg.Validate() => error
// after
cfg := &redis.AutoPipelineOptions{NumShards: 0} // auto
// or an explicit positive count (note: >1 on async face requires Unordered)
cfg := &redis.AutoPipelineOptions{NumShards: 4, Unordered: true} Defensive patterns
Strategy: validation
Validate before calling
func sanitizeNumShards(n int) int {
if n < 0 {
return 0 // auto instead of an invalid negative
}
return n
} Try / catch
if err := cfg.Validate(); err != nil {
if strings.Contains(err.Error(), "NumShards") {
cfg.NumShards = 0 // reset to auto
}
} Prevention
- Use 0 for 'auto' NumShards, never a negative.
- Clamp config values to >= 0 at load time.
- Remember NumShards >1 on the async face additionally requires Unordered:true.
When it happens
Trigger: Setting AutoPipelineOptions.NumShards to a negative number. Config deserialization producing a negative from a missing/invalid field. Sign errors.
Common situations: Config parsing bugs that yield negatives. Using -1 as an 'auto' sentinel when zero is the documented auto value. Arithmetic underflow in computed shard counts.
Related errors
- redis: AutoPipelineOptions.MaxBatchSize=%d must be >= 0
- redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0
- redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >
- redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0
- redis: AutoPipelineOptions.MaxConcurrentBatches=%d requires
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/9b54ff00287186c0.json.
Report an issue: GitHub.