{"id":"9b54ff00287186c0","repo":"go-redis/redis","slug":"redis-autopipelineoptions-numshards-d-must-be","errorCode":null,"errorMessage":"redis: AutoPipelineOptions.NumShards=%d must be >= 0","messagePattern":"redis: AutoPipelineOptions\\.NumShards=(.+?) must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"autopipeline.go","lineNumber":237,"sourceCode":"\t\t\t\"or keep MaxConcurrentBatches=1 for an ordered stream\", cfg.MaxConcurrentBatches)\n\t}\n\t// Reject obviously-wrong negatives so a typo surfaces at construction rather\n\t// than being silently coerced to a default. Zero is allowed and means \"use\n\t// the default\" (MaxBatchSize) or \"no delay\" (MaxFlushDelay).\n\tif cfg.MaxBatchSize < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxBatchSize=%d must be >= 0\", cfg.MaxBatchSize)\n\t}\n\tif cfg.MaxBatchBytes < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0\", cfg.MaxBatchBytes)\n\t}\n\tif cfg.MaxConcurrentBatches < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >= 0\", cfg.MaxConcurrentBatches)\n\t}\n\tif cfg.MaxFlushDelay < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0\", cfg.MaxFlushDelay)\n\t}\n\tif cfg.NumShards < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.NumShards=%d must be >= 0\", cfg.NumShards)\n\t}\n\tif cfg.AdaptiveDelay && cfg.MaxFlushDelay <= 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.AdaptiveDelay requires MaxFlushDelay > 0 \" +\n\t\t\t\"(adaptive delay scales MaxFlushDelay by queue fill; with no MaxFlushDelay it would \" +\n\t\t\t\"silently disable batch accumulation entirely)\")\n\t}\n\treturn nil\n}\n\n// cmdableClient is an interface for clients that support pipelining.\n// Both Client and ClusterClient implement this interface. It embeds\n// UniversalClient (Cmdable + Process + Do + AddHook + Watch + Subscribe... +\n// Close + PoolStats) so the AutoPipeliner can delegate the non-batched surface\n// back to the underlying client and itself satisfy UniversalClient.\ntype cmdableClient interface {\n\tUniversalClient\n\t// processPipelineHook is the hook-wrapped []Cmder pipeline entry — the same\n\t// method Pipeline.Exec is wired to (see Client.Pipeline). The flusher","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/autopipeline.go#L219-L255","documentation":"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.","triggerScenarios":"Setting AutoPipelineOptions.NumShards to a negative number. Config deserialization producing a negative from a missing/invalid field. Sign errors.","commonSituations":"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.","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."],"exampleFix":"// before\ncfg := &redis.AutoPipelineOptions{NumShards: -1}\n// cfg.Validate() => error\n\n// after\ncfg := &redis.AutoPipelineOptions{NumShards: 0} // auto\n// or an explicit positive count (note: >1 on async face requires Unordered)\ncfg := &redis.AutoPipelineOptions{NumShards: 4, Unordered: true}","handlingStrategy":"validation","validationCode":"func sanitizeNumShards(n int) int {\n    if n < 0 {\n        return 0 // auto instead of an invalid negative\n    }\n    return n\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"NumShards\") {\n        cfg.NumShards = 0 // reset to auto\n    }\n}","preventionTips":["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."],"tags":["autopipeline","validation","configuration","sharding","value-error"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}