The Benefits of Using Redis with Magento 2

Why Redis and Magento 2 Are a Perfect Match
If you're running a Magento 2 store, you've probably heard about Redis. But what exactly is it, and why should you care? Redis is an in-memory data structure store that acts as a cache, database, and message broker. When paired with Magento 2, it can significantly boost your store's performance, making it faster and more scalable.
In this post, we'll explore how Redis works with Magento 2, the benefits it brings, and how to set it up step by step. Whether you're new to Redis or just looking to optimize your Magento store, this guide will help you get started.
What Is Redis?
Redis stands for Remote Dictionary Server. It's an open-source, in-memory key-value store that supports various data structures like strings, hashes, lists, and sets. Unlike traditional databases that rely on disk storage, Redis keeps data in memory, which makes it incredibly fast.
Here’s why Redis is a game-changer for Magento 2:
- Blazing Fast Performance – Since Redis stores data in RAM, read and write operations happen at lightning speed.
- Reduced Database Load – By caching frequently accessed data, Redis minimizes direct database queries.
- Scalability – Redis can handle high traffic without breaking a sweat.
- Session Storage – It’s perfect for managing user sessions efficiently.
How Redis Improves Magento 2 Performance
Magento 2 is a powerful eCommerce platform, but it can be resource-heavy. Redis helps by:
- Speeding Up Page Loads – Caching product pages, categories, and blocks reduces server response time.
- Optimizing Checkout – Faster session handling means smoother checkout experiences.
- Handling Traffic Spikes – Redis efficiently manages sudden surges in visitors.
- Reducing Server Costs – Less database load means you can run Magento on smaller servers.
Setting Up Redis with Magento 2
Now, let’s get into the nitty-gritty of integrating Redis with Magento 2. Follow these steps to configure Redis as your cache and session storage.
Step 1: Install Redis
First, you need Redis installed on your server. If you're using a Linux-based system, run:
sudo apt-get update
sudo apt-get install redis-server
sudo systemctl enable redis
sudo systemctl start redis
For Windows, you can use Microsoft’s Redis port.
Step 2: Configure Magento to Use Redis
Next, update Magento’s env.php
file to enable Redis caching. Open app/etc/env.php
and add the following under the 'cache'
section:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '0',
'password' => '',
],
],
],
],
For session storage, add this under the 'session'
section:
'session' => [
'save' => 'redis',
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'password' => '',
'timeout' => '2.5',
'persistent_identifier' => '',
'database' => '1',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '1',
'max_concurrency' => '6',
'break_after_frontend' => '5',
'break_after_adminhtml' => '30',
'first_lifetime' => '600',
'bot_first_lifetime' => '60',
'bot_lifetime' => '7200',
'disable_locking' => '0',
'min_lifetime' => '60',
'max_lifetime' => '2592000'
],
],
Step 3: Verify Redis Is Working
After saving the changes, clear Magento’s cache:
php bin/magento cache:flush
Then, check if Redis is storing data by running:
redis-cli monitor
If you see activity, Redis is successfully caching your Magento data!
Advanced Redis Configurations
Want to take Redis further? Here are some optimizations:
1. Use Separate Redis Databases
Magento recommends using different Redis databases for cache, sessions, and full-page cache. Update your env.php
accordingly:
'cache' => [
'frontend' => [
'default' => [
'id_prefix' => 'abc_',
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '0',
],
],
'page_cache' => [
'id_prefix' => 'def_',
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
],
],
],
],
2. Enable Redis Compression
To save memory, enable compression for large cached objects:
'compression_threshold' => '2048',
'compression_library' => 'lzf',
3. Optimize Redis for High Traffic
If your store gets heavy traffic, tweak Redis settings in /etc/redis/redis.conf
:
maxmemory 2gb
maxmemory-policy allkeys-lru
This ensures Redis doesn’t consume too much RAM.
Common Redis Issues & Fixes
While Redis is powerful, you might encounter some issues:
- Redis Running Out of Memory → Set
maxmemory
inredis.conf
. - Connection Errors → Verify Redis is running (
sudo systemctl status redis
). - Slow Performance → Check if Redis is properly configured in
env.php
.
Final Thoughts
Redis is a must-have for any Magento 2 store looking to improve speed and scalability. By caching data in memory, it reduces database load and ensures a smoother shopping experience for customers.
If you're on the fence about using Redis, give it a try—your store (and visitors) will thank you!
Need help setting up Redis on your Magento store? Check out our hosting solutions for optimized Magento performance.