PHPフレームワークYiiシリーズチュートリアル(3):統合Redis

2890 ワード

1  Redis
   /usr/local/src ,     redis:

$ wgethttp://redis.googlecode.com/files/redis-2.6.12.tar.gz

$ tar xzf redis-2.6.12.tar.gz

$ cd redis-2.6.12

$ make

 

  redis-2.6.12  ,  redis.conf:

daemonize yes

 

     :

$src/redis-server redis.conf

 

             :

         $src/redis-cli

redis> set foo bar

OK

redis> get foo

"bar"

2  Yii Redis  
       Yii  :

Ø  Rediscache:  predis(Redis  PHP     ),    Redis for PHP  。

Ø  YiiRedis:  phpredis   ,    Redis for PHP  。

    Rediscache  ,      Redis for PHP  。

2.1    
       Rediscache  :

http://www.yiiframework.com/extension/rediscache/files/redis.zip

 

      helloyii/app/protected/extensions :

            :helloyii/app/protected/extensions/redis/CredisCache.php

2.2  Rediscache
1.helloyii/app/protected/config/main.php

===============================================================================

 return array(

 'components' => array(

   …

   'cache'=>array(

    'class'=>'ext.redis.CRedisCache',     //  protected/extensions/redis/CredisCache.php

    'servers'=>array(

     array(

      'host'=>'127.0.0.1',

      'port'=>6379,

     ),

    ),

   ),

  ),

  …

 );

3  Yii   Redis  
3.1    
 GitHub     https://github.com/lincsanders/PRedisCacheHttpSession

 

   helloyii/app/protected/extensions :

            :

         helloyii/app/protected/extensions/PredisCacheHttpSession/PRedisCacheHttpSession.php

3.2  PRedisCacheHttpSession
'session'=>array(

'class' =>'ext.PRedisCacheHttpSession.PRedisCacheHttpSession',

'database' => 9,

),

  :      database        ,    Redis      。

4     
                。

 

2.helloyii/app/protected/controllers/CacheController.php

===============================================================================

class CacheController extends CController

{

 public function actionFetch($key, $value)

  {

  Yii::app()->cache->set($key, $value);

  $data = Yii::app()->cache->get($key);

  Yii::app()->getController()->render('result',array('data'=>$data));

  }

}

 

3.helloyii/app/protected/views/cache/result.php

===============================================================================

<?php

 echo$data;

?>

 

    :http://helloyii.com/app/index.php?r=cache/fetch&key=a&value=b

    redis-cli              :

    redis-cli       :

$ src/redis-cli

redis> keys ‘*’

…

 

    
1      

http://redis.io/download

 

2 Yii Redis  1:rediscache

http://www.yiiframework.com/extension/rediscache/

 

3 Yii Redis  2:yiiredis

https://github.com/phpnode/YiiRedis

 

4 Yii CCache   API

http://www.yiichina.com/api/CCache#get-detail

 

5 Redis YiiFramework    

http://denghai260.blog.163.com/blog/static/726864092012323101628773/