{"id":"a438aafe59247192","repo":"go-redis/redis","slug":"redis-autopipelineoptions-maxflushdelay-s-must-b","errorCode":null,"errorMessage":"redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0","messagePattern":"redis: AutoPipelineOptions\\.MaxFlushDelay=(.+?) must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"autopipeline.go","lineNumber":234,"sourceCode":"\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... +\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 {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/autopipeline.go#L216-L252","documentation":"Returned by AutoPipelineOptions.Validate when MaxFlushDelay is negative. Zero is allowed (meaning no coalescing delay — flush immediately); negative durations are rejected as configuration errors. MaxFlushDelay is a time.Duration; the error formats it with %s.","triggerScenarios":"Setting AutoPipelineOptions.MaxFlushDelay to a negative time.Duration (e.g. -1 * time.Millisecond, or a zero-value subtraction that underflows). Config parsing that yields a negative duration.","commonSituations":"Duration arithmetic that produces a negative. Config files encoding a negative delay. Using a negative to mean 'disabled' when zero is the documented 'no delay' value.","solutions":["Set MaxFlushDelay to 0 (no coalescing wait, default) or a positive duration like 100 * time.Microsecond.","Use 0 for 'no delay' rather than a negative.","Guard duration computations to clamp at zero minimum."],"exampleFix":"// before\ncfg := &redis.AutoPipelineOptions{MaxFlushDelay: -100 * time.Microsecond}\n// cfg.Validate() => error\n\n// after\ncfg := &redis.AutoPipelineOptions{MaxFlushDelay: 0}                    // no delay\n// or\ncfg := &redis.AutoPipelineOptions{MaxFlushDelay: 100 * time.Microsecond} // batch coalescing","handlingStrategy":"validation","validationCode":"func sanitizeFlushDelay(d time.Duration) time.Duration {\n    if d < 0 {\n        return 0 // no delay instead of an invalid negative\n    }\n    return d\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"MaxFlushDelay\") {\n        cfg.MaxFlushDelay = 0 // reset to no-delay default\n    }\n}","preventionTips":["Use 0 for 'no coalescing delay' MaxFlushDelay, never a negative.","Clamp duration computations to a minimum of zero.","Validate duration config values at load time."],"tags":["autopipeline","validation","configuration","duration","value-error"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}