Php 如何在CodeIgniter中实现Redis?
我通过以下方式获得教程: 我试着这样做: Config(Php 如何在CodeIgniter中实现Redis?,php,codeigniter,redis,Php,Codeigniter,Redis,我通过以下方式获得教程: 我试着这样做: Config(application\Config\redis.php): 控制器: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Redis_tes extends CI_Controller { public function __construct() { parent::__construct()
application\Config\redis.php
):
控制器:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Redis_tes extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->driver('cache', array('adapter' => 'redis', 'backup' => 'file'));
}
public function index() {
// die('tes');
if($this->cache->redis->is_supported() || $this->cache->file->is_supported()) {
$var1 = $this->cache->get('cache_var1');
} else {
$cache_var1 = $this->_model_data->get_var1();
$this->cache->save('cache_var1', $cache_var1);
}
}
}
?>
我运行http://localhost/app_redis/redis_tes
,这会产生以下错误:
遇到错误
请求的驱动程序无效:CI\U缓存\U redis
有什么办法可以解决我的问题吗?看看这里:
尝试使用此库。不太确定这意味着什么,但@首先我想看看文件是否在这里-看看@/system/libraries/Cache/drivers/-是否有缓存\u redis文件?您使用哪一版本的CI?使用此软件包:欢迎提供指向潜在解决方案的链接,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久脱机。从repo自述中可以看出:“此库已弃用。我们建议迁移到Predis。”以下库使用Predis,并提供了许多很酷的功能:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Redis_tes extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->driver('cache', array('adapter' => 'redis', 'backup' => 'file'));
}
public function index() {
// die('tes');
if($this->cache->redis->is_supported() || $this->cache->file->is_supported()) {
$var1 = $this->cache->get('cache_var1');
} else {
$cache_var1 = $this->_model_data->get_var1();
$this->cache->save('cache_var1', $cache_var1);
}
}
}
?>