I get the tutorial in:
http://yaminnoor.com/redis-codeigniter/
https://codeigniter.com/user_guide/libraries/caching.html#redis
I try it like this:
Config (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:
An Error Was Encountered
Invalid driver requested: CI_Cache_redis
Any solution to solve my problem?
Look here: https://github.com/joelcox/codeigniter-redis Try to use this library.
Update : This library is deprecated. Author recommends to migrate on Predis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With