{"id":20,"date":"2020-11-26T15:58:17","date_gmt":"2020-11-26T14:58:17","guid":{"rendered":"https:\/\/www.hostgento.com\/blog\/?p=20"},"modified":"2022-01-24T17:43:02","modified_gmt":"2022-01-24T17:43:02","slug":"come-configurare-redis-per-magento-2","status":"publish","type":"post","link":"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/","title":{"rendered":"Come configurare Redis per Magento 2"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Redis \u00e8 un metodo di memorizzazione nella cache che pu\u00f2 aumentare la velocit\u00e0 del backend e del frontend del tuo negozio.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Questo articolo spiegher\u00e0 come configurare Redis nel tuo negozio Magento 2 e come lavorare con redis-cli.<\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Indice dei contenuti<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6af5c3d62f44a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6af5c3d62f44a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Configurare_Redis_Cache_per_Magento_2\" >Configurare Redis Cache per Magento 2<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Configura_Redis_Cache_per_Magento_2_tramite_la_riga_di_comando\" >Configura Redis Cache per Magento 2 tramite la riga di comando<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Configura_Redis_Cache_per_Magento_2_modificando_il_file_envphp\" >Configura Redis Cache per Magento 2 modificando il file env.php<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Configurare_Redis_Full_Page_Caching_per_Magento_2\" >Configurare Redis Full Page Caching per Magento 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Svuota_la_Cache\" >Svuota la Cache<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Modifica_della_libreria_di_compressione\" >Modifica della libreria di compressione<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Configura_Magento_2_per_utilizzare_Redis_come_Session_Store\" >Configura Magento 2 per utilizzare Redis come Session Store<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Abilita_seconda_istanza_Redis_per_le_sessioni\" >Abilita seconda istanza Redis per le sessioni<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Verifica_se_le_tue_sessioni_sono_archiviate_in_Redis\" >Verifica se le tue sessioni sono archiviate in Redis<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Risoluzione_dei_problemi\" >Risoluzione dei problemi<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.bhoost.com\/it\/piattaforme-ecommerce\/magento\/come-configurare-redis-per-magento-2\/#Bot\" >Bot<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Configurare_Redis_Cache_per_Magento_2\"><\/span><span style=\"font-weight: 400\">Configurare Redis Cache per Magento 2<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Ci sono due modi per configurare Redis Cache per Magento 2. Puoi eseguire un comando che aggiorna automaticamente <\/span><i><span style=\"font-weight: 400\">env.php<\/span><\/i><span style=\"font-weight: 400\"> con i dettagli corretti oppure puoi modificare manualmente il file <\/span><i><span style=\"font-weight: 400\">env.php<\/span><\/i><span style=\"font-weight: 400\">.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configura_Redis_Cache_per_Magento_2_tramite_la_riga_di_comando\"><\/span><span style=\"font-weight: 400\">Configura Redis Cache per Magento 2 tramite la riga di comando<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400\">Puoi utilizzare il comando seguente per abilitare la memorizzazione nella cache del backend Redis:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">cd \/data\/web\/magento2<\/span><\/pre>\n<pre><span style=\"font-weight: 400\">bin\/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0<\/span><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Configura_Redis_Cache_per_Magento_2_modificando_il_file_envphp\"><\/span><span style=\"font-weight: 400\">Configura Redis Cache per Magento 2 modificando il file env.php<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400\">Per abilitare la memorizzazione nella cache in Redis, estendi il tuo <\/span><i><span style=\"font-weight: 400\">\/data\/web\/magento2\/app\/etc\/env.php<\/span><\/i><span style=\"font-weight: 400\"> con il seguente frammento. Aggiungilo tra le chiavi della cache. (Senza la chiave della cache nello snippet)<\/span><\/p>\n<pre><span style=\"font-weight: 400\">'cache' =&gt; array(<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0'frontend' =&gt; array(<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'default' =&gt; array(<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend' \u00a0 \u00a0 \u00a0 \u00a0 =&gt; 'Cm_Cache_Backend_Redis',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend_options' =&gt; array(<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'server' =&gt; '127.0.0.1',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'port' \u00a0 =&gt; '6379',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">),<\/span><\/pre>\n<p><span style=\"font-weight: 400\">Ora svuota la cache:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">rm -rf \/data\/web\/magento2\/var\/cache\/*<\/span>\r\n\r\n<span style=\"font-weight: 400\">redis-cli flushall<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Configurare_Redis_Full_Page_Caching_per_Magento_2\"><\/span><span style=\"font-weight: 400\">Configurare Redis Full Page Caching per Magento 2<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Per abilitare il caching delle pagine Redis, estendi il tuo <\/span><i><span style=\"font-weight: 400\">`\/ data \/ web \/ magento2 \/ app \/ etc \/ env.php`<\/span><\/i><span style=\"font-weight: 400\"> con il seguente frammento.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Dovresti incollarlo tra le chiavi `cache`, quindi lascia fuori il tag cache in questo frammento.<\/span><\/p>\n<pre><span style=\"font-weight: 400\">'cache' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'frontend' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'default' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend' \u00a0 \u00a0 \u00a0 \u00a0 =&gt; 'Cm_Cache_Backend_Redis',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend_options' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'server' =&gt; '127.0.0.1',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'port' \u00a0 =&gt; '6379',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Start of snippet<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'page_cache' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend' \u00a0 \u00a0 \u00a0 \u00a0 =&gt; 'Cm_Cache_Backend_Redis',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'backend_options' =&gt; array (<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'server'\u00a0 \u00a0 \u00a0 \u00a0 =&gt; '127.0.0.1',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'port'\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; '6379',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'database'\u00a0 \u00a0 \u00a0 =&gt; '1',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'compress_data' =&gt; '0',<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ End of snippet<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0),<\/span>\r\n\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Un esempio completo puoi visualizzarlo <\/span><a href=\"https:\/\/gist.github.com\/hn-support\/4bf9575e7896abf57dff2b5ac15f05ef\"><span style=\"font-weight: 400\">qui<\/span><\/a><\/p>\n<p><span style=\"font-weight: 400\">Ora svuota la cache:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">rm -rf \/data\/web\/magento2\/var\/cache\/*<\/span>\r\n\r\n<span style=\"font-weight: 400\">redis-cli flushall<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Svuota_la_Cache\"><\/span><span style=\"font-weight: 400\">Svuota la Cache<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Per svuotare la cache di Magento, cancella il database Redis corrispondente al database Redis configurato:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">redis-cli -n $db flushdb<\/span><\/pre>\n<p><span style=\"font-weight: 400\">o in alternativa<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">n98-magerun2<\/span><\/i><span style=\"font-weight: 400\"> o lo strumento cli di Magento:<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre><span style=\"font-weight: 400\">## Flush using n98-magerun2<\/span>\r\n\r\n<span style=\"font-weight: 400\">n98-magerun2 cache:flush<\/span>\r\n\r\n\r\n<\/pre>\n<pre><span style=\"font-weight: 400\">## Flush using magento cli<\/span>\r\n\r\n<span style=\"font-weight: 400\">cd \/data\/web\/magento2 &amp;&amp; php bin\/magento cache:flush<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Per svuotare tutte le sessioni, cache ecc. (Svuotare l&#8217;intera istanza di Redis), utilizzare il seguente comando:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">redis-cli flushall<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Modifica_della_libreria_di_compressione\"><\/span><span style=\"font-weight: 400\">Modifica della libreria di compressione<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">\u00c8 possibile utilizzare la libreria di compressione &#8220;Snappy&#8221;. Maggiori informazioni su Snappy possono essere trovate nel log delle modifiche: <\/span><a href=\"https:\/\/changelog.hypernode.com\/changelog\/release-4224\/\"><span style=\"font-weight: 400\">Release-4224<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Per utilizzare la libreria di compressione Snappy per la cache di Redis devi aggiungere <\/span><i><span style=\"font-weight: 400\">&#8216;compression_library&#8217; =&gt; &#8216;snappy&#8217;<\/span><\/i><span style=\"font-weight: 400\">, nel tuo <\/span><i><span style=\"font-weight: 400\">env.php<\/span><\/i><span style=\"font-weight: 400\"> sotto:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">&#8216;page_cache&#8217; =&gt; array (<\/span><\/p>\n<p><span style=\"font-weight: 400\">&#8216;backend&#8217; \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;Cm_Cache_Backend_Redis&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">&#8216;backend_options&#8217; =&gt; array (<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Configura_Magento_2_per_utilizzare_Redis_come_Session_Store\"><\/span><span style=\"font-weight: 400\">Configura Magento 2 per utilizzare Redis come Session Store<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Puoi usare Redis anche per memorizzare le sessioni!<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">In questo modo le sessioni vengono archiviate in memoria, rendendo il negozio pi\u00f9 veloce e utilizzando meno IO rispetto a quando si utilizza MySQL o file come archivio di sessione.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Configura Magento 2 per archiviare le sessioni in Redis<\/span><\/p>\n<p><span style=\"font-weight: 400\">Poich\u00e9 Magento 2 supporta completamente Redis, non \u00e8 necessario installare estensioni aggiuntive per configurare Redis.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Tutto quello che devi fare \u00e8 estendere la tua <\/span><i><span style=\"font-weight: 400\">app \/ etc \/ env.php<\/span><\/i><span style=\"font-weight: 400\"> e svuotare la cache.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Per abilitare l&#8217;archiviazione della sessione in Redis, estendi il tuo <\/span><i><span style=\"font-weight: 400\">\/data\/web\/magento2\/app\/etc\/env.php<\/span><\/i><span style=\"font-weight: 400\"> con il seguente frammento:<\/span><\/p>\n<p><span style=\"font-weight: 400\">&#8216;session&#8217; =&gt; array(<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0&#8216;save&#8217; =&gt; &#8216;redis&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0&#8216;redis&#8217; =&gt; array(<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;host&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;redismaster&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;port&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;6379&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;password&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;timeout&#8217; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;2.5&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;persistent_identifier&#8217; =&gt; &#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;database&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;2&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;compression_threshold&#8217; =&gt; &#8216;2048&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;compression_library&#8217; \u00a0 =&gt; &#8216;gzip&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;log_level&#8217; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;1&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;max_concurrency&#8217; \u00a0 \u00a0 \u00a0 =&gt; &#8216;6&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;break_after_frontend&#8217;\u00a0 =&gt; &#8216;5&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;break_after_adminhtml&#8217; =&gt; &#8217;30&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;first_lifetime&#8217;\u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;600&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;bot_first_lifetime&#8217;\u00a0 \u00a0 =&gt; &#8217;60&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;bot_lifetime&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;7200&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;disable_locking&#8217; \u00a0 \u00a0 \u00a0 =&gt; &#8216;0&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;min_lifetime&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8217;60&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;max_lifetime&#8217;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 =&gt; &#8216;2592000&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0),<\/span><\/p>\n<p><span style=\"font-weight: 400\">),<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ora aggiorna la cache<\/span><\/p>\n<p><span style=\"font-weight: 400\">rm -rf \/data\/web\/magento2\/var\/cache\/*<\/span><\/p>\n<p><span style=\"font-weight: 400\">redis-cli flushall<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Abilita_seconda_istanza_Redis_per_le_sessioni\"><\/span><span style=\"font-weight: 400\">Abilita seconda istanza Redis per le sessioni<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Abbiamo reso possibile abilitare una seconda istanza Redis pi\u00f9 su misura per il salvataggio dei dati di sessione (maggiori informazioni possono essere trovate nel nostro changelog)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Per abilitare la seconda istanza Redis per le sessioni, esegui il comando: <\/span><i><span style=\"font-weight: 400\">systemctl settings redis_persistent_instance &#8211;value True<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Dopo aver abilitato la seconda istanza Redis \u00e8 necessario aggiornare il file <\/span><i><span style=\"font-weight: 400\">\/data\/web\/public\/app\/etc\/local.xml<\/span><\/i><span style=\"font-weight: 400\"> e modificare il valore della porta in 6378 invece del 6379 predefinito. Inoltre \u00e8 necessario aggiungere la seguente riga al proprio crontab :<\/span><\/p>\n<pre><i><span style=\"font-weight: 400\">* * * * * redis-cli -p 6378 bgsave<\/span><\/i><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Verifica_se_le_tue_sessioni_sono_archiviate_in_Redis\"><\/span><span style=\"font-weight: 400\">Verifica se le tue sessioni sono archiviate in Redis<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Per verificare se la tua configurazione funziona correttamente, cancella prima il session store:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">rm \/ data \/ web \/ public \/ var \/ sessions \/ *<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Ora apri il sito nel tuo browser e premi F5 alcune volte o accedi al pannello di amministrazione.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Se tutto va bene, nessun file di sessioni aggiuntive dovrebbe essere scritto in<\/span><i><span style=\"font-weight: 400\"> \/ data \/ web \/ var \/ sessions<\/span><\/i><span style=\"font-weight: 400\">, ma invece nel database Redis:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">redis-cli -n 2 keys \\*<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Risoluzione_dei_problemi\"><\/span><span style=\"font-weight: 400\">Risoluzione dei problemi<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Una breve nota, quando ti imbatti nel limite massimo di memoria configurato, assicurati che le chiavi Redis necessarie siano impostate su volatile (assicurati una scadenza). In caso contrario, l&#8217;intera memoria configurata allocata si riempir\u00e0 e Redis si &#8220;bloccher\u00e0&#8221;.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Quando la memoria dell&#8217;istanza Redis \u00e8 piena e arriva una nuova scrittura, Redis rimuove le chiavi per fare spazio alla scrittura in base alla policy maxmemory dell&#8217;istanza. Questa \u00e8 chiamata politica di sfratto.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In alcuni casi, vediamo che quando Redis raggiunge il limite configurato e cerca di far scadere le chiavi per fare spazio, la politica di sfratto si blocca in un ciclo. Ci\u00f2 significa che le chiavi non scadranno e Redis raggiunge il limite.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Una soluzione temporanea \u00e8 svuotare la cache di Redis, puoi farlo usando il comando flushall:<\/span><\/p>\n<pre><span style=\"font-weight: 400\">redis-cli flushall<\/span><\/pre>\n<p><span style=\"font-weight: 400\">Questo eliminer\u00e0 tutti i database Redis disponibili. Tieni presente che questa \u00e8 solo una soluzione temporanea. La causa sottostante \u00e8 nel codice dell&#8217;applicazione e deve essere risolta in modo permanente.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Una guida pi\u00f9 estesa sulla configurazione delle cache Redis pu\u00f2 essere trovata nelle <a href=\"https:\/\/devdocs.magento.com\/guides\/v2.3\/config-guide\/redis\/redis-pg-cache.html\">pagine della guida di Magento<\/a>.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bot\"><\/span><span style=\"font-weight: 400\">Bot<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Come sai, le sessioni del tuo negozio online possono essere memorizzate anche su Redis. Se utilizzi la memorizzazione nella cache di Redis e archivi le sessioni anche in Redis, dovrai condividere la memoria Redis disponibile. Questo non dovrebbe essere un problema, tuttavia abbiamo visto scenari in cui un negozio memorizza le sue sessioni in Redis e ha avuto alcuni robot \/ crawler aggressivi che visitano il negozio. Ci\u00f2 ha comportato la memorizzazione di una quantit\u00e0 di sessioni molto maggiore del solito in Redis, il che causa il riempimento della memoria di Redis in pochissimo tempo e l&#8217;arresto anomalo di Redis.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Se vuoi avere una visione pi\u00f9 dettagliata del traffico dei bot puoi usare il comando pnl <\/span><i><span style=\"font-weight: 400\">&#8211;yesterday &#8211;php &#8211;bots &#8211;fields ua | ordina | uniq -c | sort -n <\/span><\/i><span style=\"font-weight: 400\">per avere una panoramica dei primi 10 bot che hanno visitato il tuo negozio online ieri.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u00e8 un metodo di memorizzazione nella cache che pu\u00f2 aumentare la velocit\u00e0 del backend e del frontend del tuo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[2],"tags":[16],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-magento","tag-magento"],"acf":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/www.bhoost.com\/it\/author\/andreasacca_vd0s1ik8\/"},"uagb_comment_info":0,"uagb_excerpt":"Redis \u00e8 un metodo di memorizzazione nella cache che pu\u00f2 aumentare la velocit\u00e0 del backend e del frontend del tuo [&hellip;]","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":2,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/posts\/20\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhoost.com\/it\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}