Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Illuminate/Cache/RedisTagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ public function entries()
*/
public function flushStaleEntries()
{
$this->store->connection()->pipeline(function ($pipe) {
$flushStaleEntries = function ($pipe) {
foreach ($this->tagIds() as $tagKey) {
$pipe->zremrangebyscore($this->store->getPrefix().$tagKey, 0, Carbon::now()->getTimestamp());
}
});
};

$connection = $this->store->connection();

if ($connection instanceof PhpRedisConnection) {
$flushStaleEntries($connection);
} else {
$connection->pipeline($flushStaleEntries);
}
}

/**
Expand Down
31 changes: 24 additions & 7 deletions tests/Integration/Cache/RedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Redis\Connections\PhpRedisClusterConnection;
use Illuminate\Redis\Connections\PredisClusterConnection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Sleep;
use Mockery as m;
use Orchestra\Testbench\TestCase;
Expand All @@ -23,12 +22,6 @@ protected function setUp(): void
{
$this->afterApplicationCreated(function () {
$this->setUpRedis();

$connection = $this->app['redis']->connection();
$this->markTestSkippedWhen(
$connection instanceof PhpRedisClusterConnection || $connection instanceof PredisClusterConnection,
'RedisStore currently does not support tags, many and some other on Redis Cluster cluster connections',
);
});

$this->beforeApplicationDestroyed(function () {
Expand Down Expand Up @@ -103,6 +96,8 @@ public function testItCanExpireWithZeroTTL()

public function testTagsCanBeAccessed()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testTagEntriesCanBeStoredForever()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testIncrementedTagEntriesProperlyTurnStale()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testPastTtlTagEntriesAreNotAdded()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testPutPastTtlTagEntriesProperlyTurnStale()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testTagsCanBeFlushedBySingleKey()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testStaleEntriesCanBeFlushed()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

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

public function testTagsCanBeFlushedWithLargeNumberOfKeys()
{
$this->markTestSkippedWithPredisClusterConnection();

Cache::store('redis')->clear();

$tags = ['large-test-'.time()];
Expand All @@ -298,4 +307,12 @@ public function testTagsCanBeFlushedWithLargeNumberOfKeys()
$keyCount = Cache::store('redis')->connection()->keys('*');
$this->assertCount(0, $keyCount);
}

protected function markTestSkippedWithPredisClusterConnection()
{
$this->markTestSkippedWhen(
$this->app['redis']->connection() instanceof PredisClusterConnection,
'This test currently fails on Predis Cluster connection',
);
}
}
Loading