Home >Backend Development >PHP Tutorial >Examples of memcache usage in Yii framework, yiimemcache_PHP tutorial

Examples of memcache usage in Yii framework, yiimemcache_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:25867browse

Memcache usage example in Yii framework, yiimemcache

The example in this article describes the usage of memcache in Yii framework. Share it with everyone for your reference. The specific analysis is as follows:

My current company uses the YII framework, and I am exposed to more things and can learn more things. I have never been exposed to memcache in my previous company. I have only heard about it, but I have never actually used it. . Now I finally have the opportunity to use it. Let’s take the project I did as an example!

The project I am working on is a mobile phone ranking, but the ranking is refreshed every 15 minutes. There is a top three in the ranking. Maybe these three people are the top three in the first 15 minutes, and maybe they are the top three in the next 15 minutes. It is someone else's top three. The product requires that as long as the top three among these people are awarded prizes, I thought about it for a long time and finally decided to use memcache to save the information of the top three on the list every 15 minutes. The code is as follows:

Copy code The code is as follows:
public function getChargeRank3()
{
          $startime='2014-04-10 00:00:00';
          $endtime='2014-04-30 23:59:59';
$sql="select top 3 user_id, sum (point) as total from table where state=5 and cp_id>=11 and cp_id<=19 and pay_time >='$startime' and pay_time<='$endtime'
group by user_id order by total desc";
          $result= Yii::app()->controller>createCommand($sql)->queryAll();
          $cache = yii::app()->cache->get($key);
           if($cache!=false)
           {
foreach ($result as $key=>$val)
                 {
//This is an internal gift code, so it is not convenient to disclose
            }
}
YII::app()->cache->set($key, $result, strtotime($endtime));//Write the top three to the cache
}

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920972.htmlTechArticleExamples of memcache usage in Yii framework, yiimemcache This article describes the usage of memcache in Yii framework. Share it with everyone for your reference. The specific analysis is as follows: The current company uses Y...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn