search
Homephp教程php手册Yii框架中memcache用法实例

这篇文章主要介绍了Yii框架中memcache用法,以实例形式分析了在Yii框架中加入memcache的具体操作方法,是非常实用的技巧,需要的朋友可以参考下

本文实例讲述了Yii框架中memcache用法。分享给大家供大家参考。具体分析如下:

在现在的公司用的是YII的框架,接触到的东西也比较多,可以学到的东西也比较多,在以前的公司没有接触过memcache,只是听过,但是从来没有真正用过。现在终于有机会使用一下了,就以我做的项目为例吧!

我做的项目是一个手机排行榜,但是排行榜每隔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='$startime' and pay_time 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));//把前三名写入缓存
}

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment