Magento currently supports many cache backends with file system, APC and Memcached being the most widely used.
Every supported cache backend bring it's own set of upsides and downside, but since there’s a lot to choose from,
one could easily assume that as far as cache backends are concerned, Magento is very well covered. To some degree
this might be sure, but when you seriously up the number of requests, none of the cache backends scale well. Besides
poor scaling, some of the cache backend implementations also suffer from serious limitations like not having support
for grouping of related cache entries, A.K.A. tagging. With this in mind, and in order to provide support for stable
and scalable cache backend, Magento are turning to Redis key-value store.
Installing Redis - Ubuntu 13.10 or later
Good news, we do not have to add new repositories to our Ubuntu system. Bad news, there is no PhpRedis package in any
of the repositories, so we must compile the thing with a little help from
PECL.So let’s proceed with installing the Redis server
(administrative user access required):
Next, we install PhpRedis extension trough PECL, inform PHP about it’s existence, enable the PHP extension and restart Apache service:
By the way you can compile by yourself:
for Ubuntu with PHP 5.5
for Ubuntu with PHP 5.3
Verifying Redis installation
At this point we should be ready to test basic operations of Redis as well as it’s PHP extension.
Verifying Redis server
To test Redis server, we simply ping it using:
If you have received your PONG, you can proceed.
Verifying PhpRedis extension
To see if Redis extension is being loaded by PHP we can grep the output of php -m shell command:
We expect string redis as a result.
Redis shell tools
Redis comes with a few tools, most useful one being it’s client software accessible trough following shell command:
FLUSHALL – clear all databases
SELECT # – select database under index #
FLUSHDB – empty currently selected database
KEYS * – list all keys from currently selected
Redis support across different Magento versions
Here are the links to community projects that brought Redis support to Magento:
After enabling Redis as cache backend, var/cache directory of your Magento installation can be emptied and should stay empty.
To check is Redis backend being used for storing cache you can run redis-cli tool and query database 1 using following Redis commands:
Cache tags cleanup cron
Redis solves most problems that affect other cache backends, but cleaning up old cache tags manually is still required.
Next step, edit crontab as this user:
and add this script to be started every night:
Using Redis session storage
Edit app/etc/local.xml to configure:
Migrate sessions to Redis
If you are implementing Redis on a live store, you should import current sessions before you proceed.
This should be done with your store in maintenance mode.Which one you use depends on whether you’ve
been using files or db session backend before implementing Redis.
If you were previously using files for storing session data:
And here’s procedure if you were previously using database for storing session data:
After enabling Redis as session backend, var/sessions directory of your Magento installation can be emptied and should stay empty.
That’s all there is to implementing Redis with Magento. I hope you found this article useful and until next time, I wish you happy coding!
What is HHVM?HipHop Virtual Machine (HHVM) is a virtual machine developed and open sourced by Facebook to process and execute programs and scripts written in PHP. Facebook developed HHVM because the regular Zend+Apache combination isn't as eff...…