Table of Contents
Using Redis with Magento 2 can really improve your store performance. Redis allows Magento cache and session management to be much faster than the default file system method. That means faster page loads, better scalability, and less server load—especially useful if you have a big or high-traffic store.
In this post, we’ll guide you through what Redis is, why you should be interested, and how to set it up properly in Magento 2.
What is Redis?
Redis is an open-source, in-memory data store used for caching and session storage. Unlike file-based caching (which reads and writes from disk), Redis works entirely in memory, thus super fast.
Why Use Redis with Magento 2?
- Super-fast caching
- Cache tagging support (perfect for Magento’s layered cache system)
- Scales across multiple servers
- Persistent data storage (data can withstand reboots)
- Magento has native support for Redis
Magento uses the file system for sessions and cache by default, which is not ideal for performance or larger shops. Switching this over to Redis can notably reduce load times.
How to Set Up Redis for Magento 2
Magento lets you use Redis for three main areas:
- Default Cache
- Full Page Cache
- Session Storage
You can configure Redis either through Magento CLI or by editing the env.php file manually.
Option 1: Configure Redis via Command Line
1. Set Redis for Default Cache
bin/magento setup:config:set --cache-backend=redis \
--cache-backend-redis-server=127.0.0.1 \
--cache-backend-redis-port=6379 \
--cache-backend-redis-db=02. Set Redis for Page Cache
bin/magento setup:config:set --page-cache=redis \
--page-cache-redis-server=127.0.0.1 \
--page-cache-redis-port=6379 \
--page-cache-redis-db=13. Set Redis for Sessions
bin/magento setup:config:set --session-save=redis \
--session-save-redis-host=127.0.0.1 \
--session-save-redis-port=6379 \
--session-save-redis-db=2 \
--session-save-redis-log-level=3Option 2: Configure Redis in env.php (Advanced Users)
You can also manually update the app/etc/env.php file with Redis settings.
Example for Cache Configuration:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '0',
'compress_data' => '1'
]
]
]
],
Example for Session Configuration:
'session' => [
'save' => 'redis',
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '2',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '1',
'max_concurrency' => '15',
'min_lifetime' => '60',
'max_lifetime' => '2592000'
]
],
How to Test If Redis Is Working
- Use redis-cli
Run this command:
redis-cli pingIf Redis is running, it should return:
PONG2. Watch Redis Activity
Run:
redis-cli monitorThen reload your Magento storefront. You should be receiving logs from Redis that it’s being used.
- Check var/cache/
If Redis is being used for caching, you shouldn’t be seeing cache files in var/cache/.
Bonus Tips
- Use separate databases for cache, page cache, and sessions (e.g., 0, 1, 2).
- Don’t store sessions in database 0 — it’s best to reserve it for general caching.
- Set compress_data to 1 to save memory when caching large data.
- If a password is required for Redis, add the password field in your config.
Conclusion
Setting up Redis for Magento 2 is one of the easiest and most effective ways to enhance your site’s performance. Whether you own a small store or a large marketplace, Redis speeds up your store and makes it more efficient.