簡體   English   中英

如何在CodeIgniter中實現Redis?

[英]How to implement Redis in CodeIgniter?

我得到了教程:

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 ,這會產生以下錯誤:

遇到了錯誤

請求的驅動程序無效:CI_Cache_redis

解決我的問題的任何解決方案?

請看這里: https//github.com/joelcox/codeigniter-redis嘗試使用此庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM