如何在CodeIgniter中实现Redis? [英] How to implement Redis in CodeIgniter?
本文介绍了如何在CodeIgniter中实现Redis?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在教程:
http: //yaminnoor.com/redis-codeigniter/
https://codeigniter.com/user_guide/libraries/caching.html#redis
我试试这样:
配置( application\config\redis.php
):
defined('BASEPATH') OR exit('No direct script access allowed');
$config['socket_type'] = 'tcp'; //`tcp` or `unix`
$config['socket'] = '/var/run/redis.sock'; // in case of `unix` socket type
$config['host'] = '127.0.0.1'; //change this to match your amazon redis cluster node endpoint
$config['password'] = NULL;
$config['port'] = 6379;
$config['timeout'] = 0;
控制器:
<?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
,会产生以下错误:
I run http://localhost/app_redis/redis_tes
, which produces the following error:
遇到错误
An Error Was Encountered
请求的驱动程序无效:CI_Cache_redis
Invalid driver requested: CI_Cache_redis
任何解决我的问题的解决方案?
Any solution to solve my problem?
推荐答案
在这里查看:
https://github.com / joelcox / codeigniter-redis
尝试使用此库。
Look here: https://github.com/joelcox/codeigniter-redis Try to use this library.
这篇关于如何在CodeIgniter中实现Redis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文