php - 如何在 CodeIgniter 中实现 Redis?

标签 php 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;

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

我运行 http://localhost/app_redis/redis_tes,它产生了以下错误:

An Error Was Encountered

Invalid driver requested: CI_Cache_redis

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

最佳答案

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

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

关于php - 如何在 CodeIgniter 中实现 Redis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36126170/

相关文章:

jquery - 使用 jQuery 在 Firefox 中单选按钮不传递值

redis - 我应该如何在 Redis 中对此进行建模?

php - PHP 中缺少 Session_start 函数

php - Wordpress SQL 选择多个元值/元键/自定义字段

php - 这是一个确定变量是否设置的测试吗

go - 如何启动多名机械 worker ?

node.js - 全选并截断redis数据库

PHP MYSQL,两张表

php - 使用 "defined"ORM :s in PHP? 的优势

php - CodeIgniter get_where order_by