1.安装Yii的Redis插件
目前主要有两种Yii插件:
Ø Rediscache:基于predis(Redis的纯PHP实现客户端),无需安装Redis for PHP扩展。
Ø YiiRedis:基于phpredis客户端,需要安装Redis for PHP扩展。
这里采用Rediscache插件,避免线上安装Redis for PHP扩展。
1.1下载安装
从以下地址下载Rediscache插件:
http://www.yiiframework.com/extension/rediscache/files/redis.zip
将插件解压到helloyii/app/protected/extensions中:
插件文件部署后的位置应为:helloyii/app/protected/extensions/redis/CredisCache.php
1.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,
),
),
),
),
…
);