Created
July 21, 2015 08:01
-
-
Save jamesnguyen101/39aaab6a42383e2fc562 to your computer and use it in GitHub Desktop.
Clear cache Item on redis server via laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* remove cache items | |
* eg : $this->clearCache(array('clips')); | |
*/ | |
public function clearCache(array $keyList) { | |
$redis = Cache::getRedis(); | |
$cursor = 0; | |
while($data = $redis->scan($cursor)) | |
{ | |
$cursor = $data[0]; | |
foreach($data[1] as $key) | |
{ | |
foreach($keyList as $keyItem) | |
{ | |
if (strpos($key, $keyItem) !== false) | |
{ | |
$redis->del($key); | |
} | |
} | |
} | |
if ($cursor == 0) break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment