Skip to content

Instantly share code, notes, and snippets.

@jamesnguyen101
Created July 21, 2015 08:01
Show Gist options
  • Save jamesnguyen101/39aaab6a42383e2fc562 to your computer and use it in GitHub Desktop.
Save jamesnguyen101/39aaab6a42383e2fc562 to your computer and use it in GitHub Desktop.
Clear cache Item on redis server via laravel
/**
* 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