Skip to content

Commit 67ca39b

Browse files
committed
add comments in the example
1 parent a85becc commit 67ca39b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,28 +527,33 @@ func (h PipelineLoggingHook) ProcessHook(next redis.ProcessHook) redis.ProcessHo
527527
func (h PipelineLoggingHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
528528
return func(ctx context.Context, cmds []redis.Cmder) error {
529529
start := time.Now()
530+
531+
// Execute the pipeline
530532
err := next(ctx, cmds)
531-
duration := time.Since(start)
532533

533-
// Log pipeline execution
534+
duration := time.Since(start)
534535
log.Printf("Pipeline executed %d commands in %v", len(cmds), duration)
535536

536-
// Check for errors in individual commands
537+
// Process individual command errors
538+
// Note: Individual command errors are already set on each cmd by the pipeline execution
537539
for _, cmd := range cmds {
538540
if cmdErr := cmd.Err(); cmdErr != nil {
539-
// Wrap individual command errors if needed
541+
// Check for specific error types using typed error functions
540542
if redis.IsAuthError(cmdErr) {
541543
log.Printf("Auth error in pipeline command %s: %v", cmd.Name(), cmdErr)
542544
} else if redis.IsPermissionError(cmdErr) {
543545
log.Printf("Permission error in pipeline command %s: %v", cmd.Name(), cmdErr)
544546
}
545547

546-
// Optionally wrap the error
548+
// Optionally wrap individual command errors to add context
549+
// The wrapped error preserves type information through errors.As()
547550
wrappedErr := fmt.Errorf("pipeline cmd %s failed: %w", cmd.Name(), cmdErr)
548551
cmd.SetErr(wrappedErr)
549552
}
550553
}
551554

555+
// Return the pipeline-level error (connection errors, etc.)
556+
// You can wrap it if needed, or return it as-is
552557
return err
553558
}
554559
}

0 commit comments

Comments
 (0)