Example of memcache usage in Yii Framework, yiimemcache_PHP tutorial

Source: Internet
Author: User
Yiimemcache is an example of memcache usage in the Yii Framework. An example of memcache usage in the Yii Framework. yiimemcache this article describes the usage of memcache in the Yii Framework. Share it with you for your reference. The specific analysis is as follows: the current company uses the memcache usage instance in the Y Yii Framework, yiimemcache

This article describes the usage of memcache in the Yii Framework. Share it with you for your reference. The specific analysis is as follows:

Currently, the company uses the YII Framework, which involves many things and many things that can be learned. in the past, the company has never been familiar with memcache, but I have heard of it, but it has never been used. Now I have a chance to use it. let's take my project as an example!

My project is a mobile phone ranking list, but the ranking list is refreshed every 15 minutes. The ranking list has one of the top three, which may be the top three in the first 15 minutes, maybe the next 15 minutes will be the top three of others, and the product requirements, as long as the top three of them are to be awarded, I think for a long time, finally, we decided to use memcache to save the top three pieces of information on the list every 15 minutes. The code is as follows:

The code is as follows:

Public function getChargeRank3 ()
{
$ Startime = '2017-04-10 00:00:00 ';
$ Endtime = '2017-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)
{
// Here is the internal gift code, which is inconvenient to reveal
}
}
YII: app ()-> cache-> set ($ key, $ result, strtotime ($ endtime); // write the top three to the cache
}

I hope this article will help you design PHP programs based on the Yii Framework.

The following example describes the usage of memcache in the Yii Framework. Share it with you for your reference. The specific analysis is as follows: the current company uses 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.