/** * 清除缓存 */ public function redisAction() { $sType = $this->getParam('type'); $oRedis = Util_Common::getRedis($sType); $oRedis->flushdb(); return $this->showMsg('清除成功!', true); }
/** * 获取当天文章分享量(分享量前10) */ public static function getDayShareNewsList($iCityID = 0, $iSize = 10) { $iKey = $iCityID . '_s_' . date('Ymd'); $redis = Util_Common::getRedis(); $aHotNews = $redis->ZREVRANGE($iKey, 0, $iSize - 1, 'WITHSCORES'); //当前城市的新闻 if ($iCityID > 0 && count($aHotNews) < $iSize) { //全国的新闻排名 $aHotNewsAlL = $redis->ZREVRANGE('0_v_' . date('Ymd'), 0, $iSize - 1, 'WITHSCORES'); if (!empty($aHotNewsAlL)) { //array_merge,不适合这里的合并数组 foreach ($aHotNewsAlL as $iKey => $value) { if (isset($aHotNews[$iKey])) { return array(); //请求失败; } $aHotNews[$iKey] = $value; } } } if (count($aHotNews) < $iSize) { //如果不足所需,通过总访问量判断 $iNeedSize = $iSize - count($aHotNews); $aMHots = self::getHotNewsList($iCityID, $iNeedSize, array_keys($aHotNews)); if (!empty($aMHots)) { $tmp = $aHotNews; $aHotNews = array(); $aHotNews['redis'] = $tmp; $aHotNews['mysql'] = $aMHots; } } return $aHotNews; }
/** * 获取缓存连接 */ protected function _getCache() { if (null == $this->_oCache) { $this->_oCache = Util_Common::getRedis('orm'); } return $this->_oCache; }