Skip to content

Instantly share code, notes, and snippets.

@jamesnguyen101
Created August 22, 2015 12:25
Show Gist options
  • Save jamesnguyen101/9523d8ce9c334703a71a to your computer and use it in GitHub Desktop.
Save jamesnguyen101/9523d8ce9c334703a71a to your computer and use it in GitHub Desktop.
clear redis keys
/**
* 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