Created
August 22, 2015 12:25
-
-
Save jamesnguyen101/9523d8ce9c334703a71a to your computer and use it in GitHub Desktop.
clear redis keys
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')); | |
* link : http://stackoverflow.com/questions/14873506/deleting-from-laravel-cache-using-pattern-for-key\ | |
oki voi redis 3.0 (die voi 3.0.3) | |
*/ | |
/* | |
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; | |
} | |
} | |
*/ | |
/** | |
oki voi redis 3.0.3 | |
*/ | |
public function clearCache(array $keyList) { | |
$redis = Cache::getRedis(); | |
foreach ($keyList as $keyItem) { | |
$keys = $redis->keys("*". $keyItem ."*"); | |
foreach ($keys as $key) { | |
$redis->del($key); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment