pipelinex.go 296 B

123456789101112131415161718
  1. package redisx
  2. import (
  3. "context"
  4. "github.com/redis/go-redis/v9"
  5. )
  6. // 管道与事务
  7. func Pipeline(ctx context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error) {
  8. pipe := getClient().Pipeline()
  9. err := fn(pipe)
  10. if err != nil {
  11. return nil, err
  12. }
  13. return pipe.Exec(ctx)
  14. }