Magento 2 and Redis: Best Practices for Caching and Performance Optimization
Magento 2 Redis best practices are essential for Magento 2 stores to achieve faster page loads and smoother customer experiences. By following proven Redis configuration and caching strategies, merchants can reduce database load, improve session reliability, and boost overall performance.
What is Redis in Magento 2?

Redis is an open-source in-memory data store commonly used for caching and session storage in Magento 2. It replaces the default file-based caching system, providing faster read/write operations and better scalability.
Key uses of Redis in Magento 2:
- Default cache storage
- Full-page cache (FPC)
- Session management
Why Use Redis for Magento 2 Caching?
Implementing Redis provides several performance benefits compared to file-based cache.
- Improved speed – reduces database queries and disk I/O.
- Scalability – supports high-traffic Magento stores.
- Session reliability – better session handling during peak loads.
- Full-page cache efficiency – faster page delivery for customers.
Best Practices for Redis Configuration in Magento 2
1. Separate Redis Instances
For large stores, use different Redis instances for:
- Default cache
- Full-page cache
- Session storage
This prevents cache conflicts and improves stability.
2. Example Redis Configuration in env.php
You can configure Redis in Magento by updating app/etc/env.php:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '0'
]
],
'page_cache' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '1'
]
]
]
],
'session' => [
'save' => 'redis',
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '2',
'timeout' => '2.5'
]
],
In this setup:
- Database
0= default cache - Database
1= full-page cache - Database
2= sessions
3. How to Enable Redis Cache in Magento 2
After configuring env.php, enable Redis cache with Magento CLI:
php bin/magento cache:enable
php bin/magento cache:status
The first command enables cache, the second checks its status.
If you want to set Full Page Cache (FPC) to use Redis:
php bin/magento config:set system/full_page_cache/caching_application 2
- 0 = Built-in application (file cache)
1= Varnish2= Redis
Finally, flush cache to apply changes:
php bin/magento cache:flush
4. Use Data Compression
Enable compress_data to reduce memory usage. It’s especially effective for full-page caching.
5. Monitor Redis Performance
Use tools like redis-cli or monitoring solutions (New Relic, Grafana) to track memory usage, eviction rates, and latency.
6. Consider Valkey as a Future-Proof Alternative
Redis license changes have led some developers to explore Valkey, a community-driven fork. Magento 2 stores can use Valkey with the same configuration as Redis for caching.
Magento 2 Redis Caching: Final Thoughts
Magento 2 Redis best practices make Redis one of the most effective tools for Magento 2 performance optimization. By separating cache instances, enabling compression, and monitoring performance, you can achieve faster page loads, higher stability, and better scalability. For future-proofing, exploring Valkey as an alternative is also a smart move.
You can read more useful articles like Magento 2 Elasticsearch vs OpenSearch – Which is Best for Your Store?.
Follow us for the more helpful posts!
We hope this is a useful post for you.