Skip to content

Commit c17a10b

Browse files
[12.x] Fixing RedisTaggedCache::flushStale with PhpRedisClusterConnection (#57837)
* [12.x] mark certain tests skipped in RedisStoreTest * [12.x] flushStaleEntries for PhpRedisCluster in RedisTagSet * [12.x] unskip test for many (fixed in #57828) * Update RedisTagSet.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 6a97fe0 commit c17a10b

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/Illuminate/Cache/RedisTagSet.php

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

8997
/**

tests/Integration/Cache/RedisStoreTest.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Redis\Connections\PhpRedisClusterConnection;
99
use Illuminate\Redis\Connections\PredisClusterConnection;
1010
use Illuminate\Support\Facades\Cache;
11-
use Illuminate\Support\Facades\Redis;
1211
use Illuminate\Support\Sleep;
1312
use Mockery as m;
1413
use Orchestra\Testbench\TestCase;
@@ -23,12 +22,6 @@ protected function setUp(): void
2322
{
2423
$this->afterApplicationCreated(function () {
2524
$this->setUpRedis();
26-
27-
$connection = $this->app['redis']->connection();
28-
$this->markTestSkippedWhen(
29-
$connection instanceof PhpRedisClusterConnection || $connection instanceof PredisClusterConnection,
30-
'RedisStore currently does not support tags, many and some other on Redis Cluster cluster connections',
31-
);
3225
});
3326

3427
$this->beforeApplicationDestroyed(function () {
@@ -103,6 +96,8 @@ public function testItCanExpireWithZeroTTL()
10396

10497
public function testTagsCanBeAccessed()
10598
{
99+
$this->markTestSkippedWithPredisClusterConnection();
100+
106101
Cache::store('redis')->clear();
107102

108103
Cache::store('redis')->tags(['people', 'author'])->put('name', 'Sally', 5);
@@ -119,6 +114,8 @@ public function testTagsCanBeAccessed()
119114

120115
public function testTagEntriesCanBeStoredForever()
121116
{
117+
$this->markTestSkippedWithPredisClusterConnection();
118+
122119
Cache::store('redis')->clear();
123120

124121
Cache::store('redis')->tags(['people', 'author'])->forever('name', 'Sally');
@@ -151,6 +148,8 @@ public function testTagEntriesCanBeIncremented()
151148

152149
public function testIncrementedTagEntriesProperlyTurnStale()
153150
{
151+
$this->markTestSkippedWithPredisClusterConnection();
152+
154153
Cache::store('redis')->clear();
155154

156155
Cache::store('redis')->tags(['votes'])->add('person-1', 0, $seconds = 1);
@@ -167,6 +166,8 @@ public function testIncrementedTagEntriesProperlyTurnStale()
167166

168167
public function testPastTtlTagEntriesAreNotAdded()
169168
{
169+
$this->markTestSkippedWithPredisClusterConnection();
170+
170171
Cache::store('redis')->clear();
171172

172173
Cache::store('redis')->tags(['votes'])->add('person-1', 0, new DateTime('yesterday'));
@@ -180,6 +181,8 @@ public function testPastTtlTagEntriesAreNotAdded()
180181

181182
public function testPutPastTtlTagEntriesProperlyTurnStale()
182183
{
184+
$this->markTestSkippedWithPredisClusterConnection();
185+
183186
Cache::store('redis')->clear();
184187

185188
Cache::store('redis')->tags(['votes'])->put('person-1', 0, new DateTime('yesterday'));
@@ -191,6 +194,8 @@ public function testPutPastTtlTagEntriesProperlyTurnStale()
191194

192195
public function testTagsCanBeFlushedBySingleKey()
193196
{
197+
$this->markTestSkippedWithPredisClusterConnection();
198+
194199
Cache::store('redis')->clear();
195200

196201
Cache::store('redis')->tags(['people', 'author'])->put('person-1', 'Sally', 5);
@@ -207,6 +212,8 @@ public function testTagsCanBeFlushedBySingleKey()
207212

208213
public function testStaleEntriesCanBeFlushed()
209214
{
215+
$this->markTestSkippedWithPredisClusterConnection();
216+
210217
Cache::store('redis')->clear();
211218

212219
Cache::store('redis')->tags(['people', 'author'])->put('person-1', 'Sally', 1);
@@ -277,6 +284,8 @@ public function testIncrementWithSerializationEnabled()
277284

278285
public function testTagsCanBeFlushedWithLargeNumberOfKeys()
279286
{
287+
$this->markTestSkippedWithPredisClusterConnection();
288+
280289
Cache::store('redis')->clear();
281290

282291
$tags = ['large-test-'.time()];
@@ -298,4 +307,12 @@ public function testTagsCanBeFlushedWithLargeNumberOfKeys()
298307
$keyCount = Cache::store('redis')->connection()->keys('*');
299308
$this->assertCount(0, $keyCount);
300309
}
310+
311+
protected function markTestSkippedWithPredisClusterConnection()
312+
{
313+
$this->markTestSkippedWhen(
314+
$this->app['redis']->connection() instanceof PredisClusterConnection,
315+
'This test currently fails on Predis Cluster connection',
316+
);
317+
}
301318
}

0 commit comments

Comments
 (0)