So I’ve been trying to setup a Redis library inside CodeIgniter3.0. My first attempt was to search on git hub which landed me on joelcox’s repo. It seemed promising with enough number of commits and contributors, but as it said it has been deprecated, I had to look further. Now since Codeigniter also provides a Caching library out of the box, I decided to give it a try.
As illustrated in the documentation fairly well, to initiate the cache on needs to write :
The only difference is the additional array argument that I passed to driver() without which I was not able to get it to work. The redis config needs to be put in a file at location application/config/redis.php. Mine looks like this :
$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';
$config['password'] = NULL;
$config['port'] = 6379;
$config['timeout'] = 0;
This is enough to get it to work, and for simple key value pairs the following two statements can be used to set and get the value :
$this->redisObj->save($key, $value, null); // save the data with infinite TTL
$this->redisObj->get($key); // get the value of the key
This is pretty handy. Although it does not provide more redis functionalities like increment or selecting all keys ( keys * ), it does the job for basic key setting/getting requirements. Looking further for a more feature rich Redis Library for CodeIgniter.