Configure Redis cache On The Magento 2, we will see how to configure Redis cache on Magento 2. We are going to explain this in 3 simple steps. Below are the steps :-
1. Install Redis on the server.
2. Use Redis for the Magento page and default cache.
The following example enables Redis page caching, sets the host to 127.0.0.1 and assigns the database number to 1. All other parameters are set to the default value.
bin/magento setup:config:set –page-cache=redis –page-cache-redis-server=127.0.0.1 –page-cache-redis-db=1
After run the above commend check env.php file and update the below redis optimization configuration.
Note – “id_prefix” will be different. So please check your “id_prefix” after run the command and replace below “id_prefix” with yours. Also update “id_prefix” in “preload_keys” with yours.
'cache' => [ 'frontend' => [ 'default' => [ 'id_prefix' => 'e35_', 'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis', 'backend_options' => [ 'server' => 'localhost', 'database' => '0', 'port' => '6379', 'password' => '', 'persistent' => '0', 'force_standalone' => '0', 'connect_retries' => '10', 'read_timeout' => '30', 'automatic_cleaning_factor' => '0', 'compress_data' => '1', 'compression_lib' => 'gzip', 'compress_tags' => '1', 'compress_threshold' => '20480', 'preload_keys' => [ 'e35_EAV_ENTITY_TYPES', 'e35_GLOBAL_PLUGIN_LIST', 'e35_DB_IS_UP_TO_DATE', 'e35_SYSTEM_DEFAULT', 'e35_M2EPRO_EXTENSION_M2EPRO_CONFIG_DATA' ] ] ], 'page_cache' => [ 'id_prefix' => 'e35_', 'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis', 'backend_options' => [ 'server' => 'localhost', 'database' => '0', 'port' => '6379', 'password' => '', 'persistent' => '0', 'connect_retries' => '10', 'read_timeout' => '30', 'automatic_cleaning_factor' => '0', 'compress_data' => '1', 'compression_lib' => 'gzip', 'compress_tags' => '1', 'compress_threshold' => '20480', 'preload_keys' => [ 'e35_EAV_ENTITY_TYPES', 'e35_GLOBAL_PLUGIN_LIST', 'e35_DB_IS_UP_TO_DATE', 'e35_SYSTEM_DEFAULT', 'e35_M2EPRO_EXTENSION_M2EPRO_CONFIG_DATA' ] ] ] ], 'allow_parallel_generation' => false ],
3. Configure Magento to use Redis for session storage
bin/magento setup:config:set –session-save=redis –session-save-redis-host=127.0.0.1 –session-save-redis-log-level=4 –session-save-redis-db=2
Related Blog – Show Popup in Magento 2