Redis, an in-memory data structure store, is the gold standard for Magento 2 Caching.
It’s very fast, reliable, and significantly reduces your load
database by handling caching operations.
You’ve installed Redis, which is an important first step. Now, let’s bridge the gap and show Magento how to use it.
This guide will walk you through the exact steps to configure Redis backend caching in Magento 2.
Redis must be installed on your server before proceeding.
Why Configure Redis Backend Cache?
Before we dive in, let’s recap why this configuration is so important:
- Incredible Speed: Redis operates completely in memory, making data retrieval a breeze
fast compared to disk or database based caches. - Reducing Database Load: By moving cache storage to Redis, your database is freed up
to handling important transactional queries, improving overall site stability and performance. - Scalability Improvements: Lighter database loading means your store can handle more
users simultaneously without performance degradation. - Centralized Cache Management: Redis provides one,
An efficient location for all your caching needs, from configuration and layout
to full page content.
Backup Your Configuration env.php file.
Safety comes first! Before making any changes, it is important to back up your files
Magento environment configuration file.
From your Magento root directory, run the following command:
cp app/etc/env.php app/etc/env.php.bak
If something goes wrong, you can easily restore the original file.
Configure Backend Cache
The essence of the configuration occurs in app/etc/env.php submit.
You need to edit this file to tell Magento to use Redis as backend caching.
Using Redis for back end cache improve overall system performance
by reducing file system load and speeding up cache read/write operations.
For best practices, it is recommended to use a Dedicated Redis
database (for example, db 0) for the backend cache to avoid conflicts with other cache sets.
The following example enables the Redis backend cache, sets the host to 127.0.0.1, and sets the database number to 1. All other parameters are set to default values.
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.--cache-backend-redis-db=1 --cache-backend-redis-port=6379
After running this command Magento 2 adds the configuration to the app/etc/env.php file.
'cache' => [
'frontend' => [
'default' => [
'backend' => '\\Cm\\Cache\\Backend\\Redis', // The Redis backend adapter
'backend_options' => [
'server' => '127.0.0.1', // Your Redis server IP
'port' => '6379', // Your Redis server port
'database' => '1', // Redis database for backend cache
// 'password' => 'your-redis-password', // Uncomment and set if you have a password
'force_standalone' => 0,
'connect_retries' => 1,
'read_timeout' => 10,
'automatic_cleaning_factor' => 0,
'compress_data' => 1,
'compress_tags' => 1,
'compress_threshold' => 20480,
'compression_lib' => 'gzip',
],
],
],
],
Main Parameters Explained:
'backend': This tells Magento to use the Cm_RedisCache module backend adapter.'server': The IP address or hostname of your Redis server
ongoing.127.0.0.1used if Redis is on the same server as Magento.'port': The port your Redis server listens on (default is6379).'database': Redis database number.
Most importantly, we use0FordefaultAnd1Forpage_cacheto separate them.'password': If your Redis instance is password-secured,
uncomment this line and add your password.
Save env.php file after making these changes.
Flush Magento Cache and Verify
Now that the configuration is ready, you need to tell Magento to do it
read the new settings and clear all existing cache.
From your Magento root directory, run:
bin/magento cache:flush
This command clears all types of cache and forces Magento to do so
rebuild it using the new Redis backend cache.
How to Verify Redis Backend Cache is Working
redis-cli
Once logged in, you can monitor live traffic. Type MONITOR and press Enter.
redis-cli> MONITOR
Now, load some pages of your Magento shop in your web browser.
You will see a stream of commands appear in your terminal window,
looks like this:
1612345678.123456 [0 127.0.0.1:54321] "GET" "zc:k:default_..." 1612345678.234567 [1 127.0.0.1:54322] "HGET" "zc:k:FPC..." ...
That [0] And [1] shows the databases used, confirming that they are both default
cache and FPC are stored in Redis. Press Ctrl+C to stop monitoring.
Reference Redis Magento 2 docs
News
Berita
News Flash
Blog
Technology
Sports
Sport
Football
Tips
Finance
Berita Terkini
Berita Terbaru
Berita Kekinian
News
Berita Terkini
Olahraga
Pasang Internet Myrepublic
Jasa Import China
Jasa Import Door to Door