一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Yii框架中memcache使用教程

时间:2014-04-18 编辑:简简单单 来源:一聚教程网

我做的项目是一个手机排行榜,但是排行榜每隔15分钟刷新一次啊,排行榜有一个前三名,可能前15分钟这三个人是前三名,也许下一个15分钟又是别人前三名了,产品要求,这些人中只要是前三名的都要发奖品,思考了好久,最终决定用memcache来保存每15分钟的榜单前三名的信息。代码如下:

 代码如下 复制代码

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)
            {
  内部为赠送礼物代码,不便透漏
            }
        }
        YII::app()->cache->set($key, $result, strtotime($endtime));//把前三名写入缓存
    }

热门栏目