|
6 | 6 | use Illuminate\Contracts\Queue\Queue as QueueContract;
|
7 | 7 | use Illuminate\Contracts\Redis\Factory as Redis;
|
8 | 8 | use Illuminate\Queue\Jobs\RedisJob;
|
| 9 | +use Illuminate\Redis\Connections\PhpRedisClusterConnection; |
| 10 | +use Illuminate\Redis\Connections\PredisClusterConnection; |
9 | 11 | use Illuminate\Support\Str;
|
10 | 12 |
|
11 | 13 | class RedisQueue extends Queue implements QueueContract, ClearableQueue
|
@@ -118,17 +120,25 @@ public function size($queue = null)
|
118 | 120 | */
|
119 | 121 | public function bulk($jobs, $data = '', $queue = null)
|
120 | 122 | {
|
121 |
| - $this->getConnection()->pipeline(function () use ($jobs, $data, $queue) { |
122 |
| - $this->getConnection()->transaction(function () use ($jobs, $data, $queue) { |
123 |
| - foreach ((array) $jobs as $job) { |
124 |
| - if (isset($job->delay)) { |
125 |
| - $this->later($job->delay, $job, $data, $queue); |
126 |
| - } else { |
127 |
| - $this->push($job, $data, $queue); |
128 |
| - } |
| 123 | + $connection = $this->getConnection(); |
| 124 | + |
| 125 | + $bulk = function () use ($jobs, $data, $queue) { |
| 126 | + foreach ((array) $jobs as $job) { |
| 127 | + if (isset($job->delay)) { |
| 128 | + $this->later($job->delay, $job, $data, $queue); |
| 129 | + } else { |
| 130 | + $this->push($job, $data, $queue); |
129 | 131 | }
|
130 |
| - }); |
131 |
| - }); |
| 132 | + } |
| 133 | + }; |
| 134 | + |
| 135 | + if ($connection instanceof PhpRedisClusterConnection) { |
| 136 | + $connection->transaction($bulk); |
| 137 | + } elseif ($connection instanceof PredisClusterConnection) { |
| 138 | + $connection->pipeline($bulk); |
| 139 | + } else { |
| 140 | + $connection->pipeline(fn () => $connection->transaction($bulk)); |
| 141 | + } |
132 | 142 | }
|
133 | 143 |
|
134 | 144 | /**
|
|
0 commit comments