Skip to content

Commit f5c84e9

Browse files
committed
[12.x] transaction for PredisClusterConnection and pipelines for PhpRedisClusterConnection
1 parent 09a66d5 commit f5c84e9

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

src/Illuminate/Cache/RedisTagSet.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,11 @@ public function entries()
7979
*/
8080
public function flushStaleEntries()
8181
{
82-
$flushStaleEntries = function ($pipe) {
82+
$this->store->connection()->pipeline(function ($pipe) {
8383
foreach ($this->tagIds() as $tagKey) {
8484
$pipe->zremrangebyscore($this->store->getPrefix().$tagKey, 0, Carbon::now()->getTimestamp());
8585
}
86-
};
87-
88-
$connection = $this->store->connection();
89-
if ($connection instanceof PhpRedisConnection) {
90-
$flushStaleEntries($connection);
91-
} else {
92-
$this->store->connection()->pipeline($flushStaleEntries);
93-
}
86+
});
9487
}
9588

9689
/**

src/Illuminate/Queue/RedisQueue.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,7 @@ public function bulk($jobs, $data = '', $queue = null)
183183
}
184184
};
185185

186-
if ($connection instanceof PhpRedisClusterConnection) {
187-
$connection->transaction($bulk);
188-
} elseif ($connection instanceof PredisClusterConnection) {
189-
$connection->pipeline($bulk);
190-
} else {
191-
$connection->pipeline(fn () => $connection->transaction($bulk));
192-
}
186+
$connection->pipeline(fn () => $connection->transaction($bulk));
193187
}
194188

195189
/**

src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ public function flushAll()
8181
}
8282
}
8383

84+
/**
85+
* Execute commands in a pipeline.
86+
*
87+
* @param callable|null $callback
88+
* @return mixed
89+
*/
90+
public function pipeline(?callable $callback = null)
91+
{
92+
// phphredis does not support pipelines for Redis Cluster
93+
return tap($this, $callback);
94+
}
95+
8496
/**
8597
* Return default node to use for cluster.
8698
*

src/Illuminate/Redis/Connections/PredisClusterConnection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Redis\Connections;
44

5+
use Illuminate\Support\Arr;
56
use Predis\Command\Redis\FLUSHALL;
67
use Predis\Command\Redis\FLUSHDB;
78
use Predis\Command\ServerFlushDatabase;
@@ -49,4 +50,16 @@ public function keys(string $pattern)
4950
}
5051
return array_merge(...$keys);
5152
}
53+
54+
/**
55+
* Execute commands in a transaction.
56+
*
57+
* @param callable|null $callback
58+
* @return mixed
59+
*/
60+
public function transaction(?callable $callback = null)
61+
{
62+
// p does not support transacation for Redis Cluster
63+
return tap($this, $callback);
64+
}
5265
}

0 commit comments

Comments
 (0)