MultiExec.php 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Redis\Traits;
  12. use Redis;
  13. use RedisCluster;
  14. use function Hyperf\Tappable\tap;
  15. trait MultiExec
  16. {
  17. /**
  18. * Execute commands in a pipeline.
  19. *
  20. * @return array|Redis
  21. */
  22. public function pipeline(?callable $callback = null)
  23. {
  24. $pipeline = $this->__call('pipeline', []);
  25. return is_null($callback) ? $pipeline : tap($pipeline, $callback)->exec();
  26. }
  27. /**
  28. * Execute commands in a transaction.
  29. *
  30. * @return array|Redis|RedisCluster
  31. */
  32. public function transaction(?callable $callback = null)
  33. {
  34. $transaction = $this->__call('multi', []);
  35. return is_null($callback) ? $transaction : tap($transaction, $callback)->exec();
  36. }
  37. }