简体   繁体   English

如何在CodeIgniter中实现Redis?

[英]How to implement Redis in CodeIgniter?

I get the tutorial in: 我得到了教程:

http://yaminnoor.com/redis-codeigniter/ http://yaminnoor.com/redis-codeigniter/

https://codeigniter.com/user_guide/libraries/caching.html#redis https://codeigniter.com/user_guide/libraries/caching.html#redis

I try it like this: 我试试这样:

Config ( application\\config\\redis.php ): 配置( 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;

Controller: 控制器:

<?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);
        }
    }
}
?>

I run http://localhost/app_redis/redis_tes , which produces the following error: 我运行http://localhost/app_redis/redis_tes ,这会产生以下错误:

An Error Was Encountered 遇到了错误

Invalid driver requested: CI_Cache_redis 请求的驱动程序无效:CI_Cache_redis

Any solution to solve my problem? 解决我的问题的任何解决方案?

请看这里: https//github.com/joelcox/codeigniter-redis尝试使用此库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM