CodeIgniter增加redis的cache driver

希望在CI中使用redis作为缓存驱动,发现官方github上已经有了:D,貌似要到3.0才正式发布,先用上吧,省事了

为了保持框架可升级操作如下,

1、将system\libraries\Cache\Cache.php复制为application\libraries\Cache\Cache.php

增加配置

protected $valid_drivers = array(

'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy', 'cache_redis'

);

2、将https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Cache/drivers/Cache_redis.php放到application\libraries\Cache\drivers下

3、测试:

$this->load->driver('cache', array('adapter' => 'redis'));

if ( ! $foo = $this->cache->get('foo'))

{

     echo 'Saving to the cache!<br />';

     $foo = 'foobarbaz!';

     // Save into the cache for 5 minutes

     $this->cache->save('foo', $foo, 300);

}

echo $foo;

猜你喜欢

转载自wtm-mac.iteye.com/blog/1628333