【问题标题】:How to implement Redis in CodeIgniter?如何在 CodeIgniter 中实现 Redis?
【发布时间】:2016-07-07 16:11:15
【问题描述】:

我得到了教程:

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

有什么办法可以解决我的问题吗?

【问题讨论】:

  • 不太清楚这意味着什么,但@first 我会看看文件是否在这里 - 看看@/system/libraries/Cache/drivers/ - 是否有 Cache_redis 文件?以及您使用哪个版本的 CI?

标签: php codeigniter redis


【解决方案1】:

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

更新:此库已弃用。作者建议迁移到 Predis。

【讨论】:

  • 始终欢迎提供指向潜在解决方案的链接,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及它存在的原因。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。
  • 来自 repo README:“此库已弃用。我们建议迁移到 Predis。”
  • 以下库使用了 Predis 并提供了很多很酷的功能:github.com/Maykonn/codeigniter-predis
猜你喜欢
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 2018-10-02
相关资源
最近更新 更多