{"id":"5fd8718bd24481bf","repo":"go-redis/redis","slug":"redis-autopipelineoptions-maxconcurrentbatches-d-5fd871","errorCode":null,"errorMessage":"redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >= 0","messagePattern":"redis: AutoPipelineOptions\\.MaxConcurrentBatches=(.+?) must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"autopipeline.go","lineNumber":231,"sourceCode":"// Options.AutoPipelineOptions is validated lazily — on the first getter\n// call, not in NewClient.\nfunc (cfg *AutoPipelineOptions) Validate() error {\n\tif cfg.MaxConcurrentBatches > 1 && !cfg.Unordered {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxConcurrentBatches=%d requires Unordered:true \"+\n\t\t\t\"(parallel batches do not preserve command ordering); set Unordered:true to allow it, \"+\n\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... +","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/autopipeline.go#L213-L249","documentation":"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.","triggerScenarios":"Setting AutoPipelineOptions.MaxConcurrentBatches to a negative number. Config deserialization producing a negative from a missing/invalid field.","commonSituations":"Config parsing bugs. Sign errors. Treating -1 as 'auto' when zero is the documented 'use default' value.","solutions":["Set MaxConcurrentBatches to 0 (default of 1) or a non-negative integer.","Use 0 instead of a negative for 'default'.","Validate at config load time."],"exampleFix":"// before\ncfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: -1}\n// cfg.Validate() => error\n\n// after\ncfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: 0} // default (1)\n// or, if >1, also set Unordered: true\ncfg := &redis.AutoPipelineOptions{MaxConcurrentBatches: 4, Unordered: true}","handlingStrategy":"validation","validationCode":"func sanitizeConcurrentBatches(n int) int {\n    if n < 0 {\n        return 0 // default (1) 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(), \"MaxConcurrentBatches\") && !strings.Contains(err.Error(), \"Unordered\") {\n        cfg.MaxConcurrentBatches = 0 // reset to default\n    }\n}","preventionTips":["Use 0 for 'default' MaxConcurrentBatches, never a negative.","Clamp config values to >= 0 at load time.","Remember values >1 additionally require Unordered:true."],"tags":["autopipeline","validation","configuration","value-error"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}