|
4 | 4 |
|
5 | 5 | use Illuminate\Cache\Events\CacheFlushed;
|
6 | 6 | use Illuminate\Cache\Events\CacheFlushing;
|
| 7 | +use Illuminate\Redis\Connections\PhpRedisConnection; |
| 8 | +use Illuminate\Redis\Connections\PredisConnection; |
7 | 9 |
|
8 | 10 | class RedisTaggedCache extends TaggedCache
|
9 | 11 | {
|
@@ -110,8 +112,46 @@ public function flush()
|
110 | 112 | {
|
111 | 113 | $this->event(new CacheFlushing($this->getName()));
|
112 | 114 |
|
113 |
| - $this->flushValues(); |
114 |
| - $this->tags->flush(); |
| 115 | + $redisPrefix = match ($this->store->connection()::class) { |
| 116 | + PhpRedisConnection::class => $this->store->connection()->client()->getOption(\Redis::OPT_PREFIX), |
| 117 | + PredisConnection::class => $this->store->connection()->client()->getOptions()->prefix, |
| 118 | + }; |
| 119 | + |
| 120 | + $cachePrefix = $redisPrefix.$this->store->getPrefix(); |
| 121 | + |
| 122 | + $cacheTags = []; |
| 123 | + $keysToBeDeleted = []; |
| 124 | + |
| 125 | + foreach ($this->tags->getNames() as $name) { |
| 126 | + $cacheTags[] = $cachePrefix.$this->tags->tagId($name); |
| 127 | + } |
| 128 | + |
| 129 | + foreach ($this->tags->entries() as $entry) { |
| 130 | + $keysToBeDeleted[] = $this->store->getPrefix().$entry; |
| 131 | + } |
| 132 | + |
| 133 | + $script = <<<'LUA' |
| 134 | + local prefix = table.remove(ARGV, 1) |
| 135 | +
|
| 136 | + for i, key in ipairs(KEYS) do |
| 137 | + redis.call('DEL', key) |
| 138 | +
|
| 139 | + for j, arg in ipairs(ARGV) do |
| 140 | + local zkey = string.gsub(key, prefix, "") |
| 141 | + redis.call('ZREM', arg, zkey) |
| 142 | + end |
| 143 | + end |
| 144 | + LUA; |
| 145 | + |
| 146 | + $this->store->connection()->eval( |
| 147 | + $script, |
| 148 | + count($keysToBeDeleted), |
| 149 | + ...$keysToBeDeleted, |
| 150 | + ...[$cachePrefix, ...$cacheTags] |
| 151 | + ); |
| 152 | + |
| 153 | + // $this->flushValues(); |
| 154 | + // $this->tags->flush(); |
115 | 155 |
|
116 | 156 | $this->event(new CacheFlushed($this->getName()));
|
117 | 157 |
|
|
0 commit comments