Php – Configure Cakephp 2.6.0 with Redis Engine

cachingcakephpperformancePHPredis

I am trying to configure cakephp ver 2.6.0 to use redis engine by default. but somehow i am not able to make it work. any help will be highly appreciated.

Things Which i have tried so far..

Configured app/config folder 2 files , core.php and bootstrap.php. , according to the guidelines provided here in this blog configure cake with redis and this blog too Another cake-redis config setup

but i keep on getting errors like.

Fatal error: Uncaught exception 'CacheException' with message 'Cache engine session is not properly configured.' in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181

CacheException: Cache engine session is not properly configured. in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181

Any help will be highly appreciated.

Best Answer

I was having the same exact issue today while trying to setup CakePHP to use Redis as the cache engine.

Coincidentally, I also read the same setup instructions from the two blogs you linked to.

The reason was that I had copied pasted the Configure::write(...) code block from the Another cake-redis config setup blog post as it is and pasted it into the file without first commenting out the Configure::write(...) code block that was already in the core.php file.

I'm assuming that you have already successfully setup Redis on Windows and have installed the PHPRedis extension without any issues.

I am using the instructions from Another cake-redis config setup here.

In your app/Config/core.php file, comment out the following block: (this was starting at line 218 in my core.php)

    Configure::write('Session', array(
    'defaults' => 'php'
));

Instead, you can put this in: (You can change the values to suit your particular needs)

Configure::write('Session', array(
'defaults' => 'cache',
'timeout' => 100,
'start' => true,
'checkAgent' => false,
'handler' => array(
    'config' => 'session'
    )
));

After this, change the value of $engine to 'Redis', so it becomes:

$engine = 'Redis';

And then, put this code in, I put this in at the very end of the file: (Again, your values can be different depending on what your setup is)

    Cache::config ('session', array (
    'Engine' => $engine,
    'Prefix' => $prefix . 'cake_session_',
    'Duration' => $duration
));

And that's it. You're done! No need to change anything else.

To make sure that Redis is working properly with CakePHP, I ran the RedisEngine Test Suite that comes with CakePHP. You need to have PHPUnit installed for this to work.

It can be accessed via http://your-cakephp-project/test.php

Click on 'Tests' under Core and then click on 'Cache/Engine/RedisEngine' If everything is working successfully, you should see all the tests pass.

Alternatively, you can use redis-cli at the command prompt to confirm that Redis is storing keys properly.

Once you have logged in by typing redis-cli, type KEYS * This should give you a list of keys related to your CakePHP setup.

An example would be the "myapp_cake_core_object_map" key.

Hope this helps.

Related Topic