Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class RedisStore extends TaggableStore implements LockProvider
{
use RetrievesMultipleKeys {
many as private manyAlias;
putMany as private putManyAlias;
}

Expand Down Expand Up @@ -92,6 +93,12 @@ public function many(array $keys)

$connection = $this->connection();

// Cluster connections do not support reading multiple values if the keys hash differently...
if ($connection instanceof PhpRedisClusterConnection ||
$connection instanceof PredisClusterConnection) {
return $this->manyAlias($keys);
}

$values = $connection->mget(array_map(function ($key) {
return $this->prefix.$key;
}, $keys));
Expand Down
11 changes: 9 additions & 2 deletions src/Illuminate/Cache/RedisTagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ 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
11 changes: 10 additions & 1 deletion src/Illuminate/Cache/RedisTaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,17 @@ protected function flushValues()
->map(fn (string $key) => $this->store->getPrefix().$key)
->chunk(1000);

$connection = $this->store->connection();
foreach ($entries as $cacheKeys) {
$this->store->connection()->del(...$cacheKeys);
if ($connection instanceof PredisClusterConnection) {
$connection->pipeline(function ($connection) use ($cacheKeys) {
foreach ($cacheKeys as $cacheKey) {
$connection->del($cacheKey);
}
});
} else {
$connection->del(...$cacheKeys);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Redis/Connections/PredisClusterConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ public function flushdb()
$node->executeCommand(tap(new $command)->setArguments(func_get_args()));
}
}

/**
* Returns the keys that match a certain pattern.
*
* @param string $pattern
* @return array
*/
public function keys(string $pattern)
{
$keys = [];
foreach ($this->client as $node) {
$keys[] = $node->keys($pattern);
}

return array_merge(...$keys);
}
}
11 changes: 2 additions & 9 deletions tests/Integration/Cache/MemoizedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Illuminate\Cache\Events\WritingKey;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
use Illuminate\Redis\Connections\PhpRedisClusterConnection;
use Illuminate\Redis\Connections\PredisClusterConnection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
Expand All @@ -33,14 +31,9 @@ protected function setUp(): void

$this->setUpRedis();

$connection = $this->app['redis']->connection();
$this->markTestSkippedWhen(
$connection instanceof PhpRedisClusterConnection || $connection instanceof PredisClusterConnection,
'flushAll and many currently not supported for Redis Cluster connections',
);

Config::set('cache.default', 'redis');
Redis::flushAll();
Redis::connection(Config::get('cache.stores.redis.connection'))->flushDb();
Redis::connection(Config::get('cache.stores.redis.lock_connection'))->flushDb();
}

protected function tearDown(): void
Expand Down
8 changes: 0 additions & 8 deletions tests/Integration/Cache/RedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Illuminate\Cache\RedisStore;
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
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 +21,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