# 批量删除redis或memcached缓存

**URL:** <https://www.shiqidu.com/t/topic/673>\
**Category:** 开发调优\
**Tags:** 互联网\
**Created:** [2019 年11 月 20 日 11:17 UTC](https://www.shiqidu.com/t/topic/673 "2019-11-20T11:17:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![dajiang](https://www.shiqidu.com/user_avatar/www.shiqidu.com/dajiang/32/468_2.png) [@dajiang](https://www.shiqidu.com/u/dajiang)\
发布日期： [2019 年11 月 20 日 11:17 UTC](https://www.shiqidu.com/t/topic/673/1 "2019-11-20T11:17:03Z")

</div>

```php
public function cleanCache(){
        $keys = $this->redis->keys(self::CACHE_PREFIX.'*');
        foreach($keys as $key){
            $r = $this->redis->delete($key);
            echo $key.'---'.$r."<br>".PHP_EOL;
            ob_flush();
            flush();
        }
    }
	
$keys = $cache->getAllKeys();
$regex = 'product_.*';
foreach($keys as $item) {
    if(preg_match('/'.$regex.'/', $item)) {
        $cache->delete($item);
    }
}

```
