Example of memcache usage in Yii framework, yiimemcache_php tutorial

Source: Internet
Author: User

Example of memcache usage in Yii framework, Yiimemcache


The examples in this paper describe the Memcache usage in Yii framework. Share to everyone for your reference. The specific analysis is as follows:

In the current company is the framework of yii, contact with more things, can learn more things, in the previous company did not contact Memcache, just heard, but never really used. Now finally have the opportunity to use, just take my project as an example!

I do the project is a mobile ranking, but the leaderboard every 15 minutes refreshed Ah, the leaderboard has a top three, perhaps the first 15 minutes of the three people are the top three, perhaps the next 15 minutes is the first three people, product requirements, as long as the top three are to send prizes, thinking for a long time, The final decision is to use Memcache to store the top three information for every 15 minutes. The code is as follows:
Copy the Code Code 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 & Gt;= ' $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)
{
Here for the inside gift code, inconvenient to disclose
}
}
Yii::app ()->cache->set ($key, $result, Strtotime ($endtime));//write the first three names to the cache
}

It is hoped that this article is helpful to the PHP program design based on YII framework.

http://www.bkjia.com/PHPjc/920972.html www.bkjia.com true http://www.bkjia.com/PHPjc/920972.html techarticle The example of memcache usages in Yii framework Yiimemcache the Memcache usage in Yii framework. Share to everyone for your reference. The specific analysis is as follows: At present the company uses the y ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.