zoukankan      html  css  js  c++  java
  • redis scan删除key的方法封装

    /**
    * @desc 迭代式的删除redis key
    * 用法:
    * $redis = BaseService::S()->getRedisConfig(Yii::$app->redis2);
    * RedisHelper::delByScan(['mindCard'], $redis);
    * @author yanglb@immatchu.com
    * @created time 2018-12-29
    * @param object $redisInstance redis数据库实例
    * @param array $matchGroup 要删除的key(可以是key的前缀)所组成的数组
    * @param int $count 一次最多删除多少条key
    * @return bool
    */
    public static function delByScan($redisInstance, array $matchGroup = [], $count = 1000)
    {
    if (empty($matchGroup)) {
    return false;
    }
    $redis = $redisInstance;
    $it = null;
    do {
    $arr_keys = $redis->scan($it, null, $count);
    if (is_array($arr_keys) && count($arr_keys) > 0) {
    foreach ($arr_keys as $key) {
    foreach ($matchGroup as $match) {
    if (strpos($key, $match) !== false) {
    $redis->del($key);
    }
    }
    }
    }
    } while ($it > 0);
    return true;
    }

  • 相关阅读:
    第 2 章 OpenStack 架构
    第 2 章 OpenStack 架构
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
    第 1 章 虚拟化
  • 原文地址:https://www.cnblogs.com/ryanlamp/p/10193881.html
Copyright © 2011-2022 走看看