CodeIgniter增加redis的cache driver

来源:互联网 发布:韩子高网络剧第二部 编辑:程序博客网 时间:2024/05/17 02:11

希望在CI中使用redis作为缓存驱动,发现官方github上已经有了,貌似要到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!
';
     $foo = 'this is redis cache!';
     // Save into the cache for 1 minutes
     $this->cache->save('foo', $foo, 60);
}
echo $foo;


0 0
原创粉丝点击