Magento借助Zend框架支持许多后端缓存。Memcache和APC是常用的。但是,Redis迅速成为Magento和其他Web应用程序的流行且功能强大的缓存系统。
Redis是开源的,BSD许可的高级键值存储,可以选择在Magento中用于后端和会话存储。它可用于缓存数据库,从而减少了对数据库资源的利用,并提供了可调整的持久性缓存。它是memcacheD的一个很好的选择。
首次加载页面时,将在服务器上查询数据库。Redis缓存查询。下次其他用户加载页面时,结果将从Redis提供,而无需查询实际数据库。它实现了一个持久的对象缓存(没有过期)。对象缓存通过在加载网页所需的内存中缓存SQL查询来工作。当主数据库服务器的数据更新时,redis中的对应密钥将失效。因此,它提供了更新的数据,而不是缓存数据。如果redis中没有可用的查询,则数据库将提供结果,并将结果添加到其缓存中。
因此,让我们开始安装它并为Magento配置它。
更新并安装redis-server。
sudo suapt-get updateapt-get install redis-server
配置Magento,
要启用该模块,请编辑
到
然后,编辑位于magento目录中的“ local.xml”文件。
改变
到
<?xml version="1.0"?><config><global><install><date><![CDATA[Tue, 04 Oct 2016 09:53:37 +0000]]></date></install><crypt><key><![CDATA[e972f3c4e8436052de805bdf1f40de0f]]></key></crypt><disable_local_modules>false</disable_local_modules><resources><db><table_prefix><![CDATA[]]></table_prefix></db><default_setup><connection><host><![CDATA[localhost]]></host><username><![CDATA[magento]]></username><password><![CDATA[magento]]></password><dbname><![CDATA[magento]]></dbname><initStatements><![CDATA[SET NAMES utf8]]></initStatements><model><![CDATA[mysql4]]></model><type><![CDATA[pdo_mysql]]></type><pdoType><![CDATA[]]></pdoType><active>1</active></connection></default_setup></resources><!-- This is a child node of config/global --><cache><backend>Cm_Cache_Backend_Redis</backend><backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket --><port>6379</port><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><database>0</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases --><password></password> <!-- Specify if your server requires authentication --><force_standalone>0</force_standalone> <!-- 0 for phpredis, 1 for standalone PHP --><connect_retries>1</connect_retries> <!-- Reduces errors due to random connection failures; a value of 1 will not retry after the first failure --><read_timeout>10</read_timeout> <!-- Set read timeout duration; phpredis does not currently support setting read timeouts --><automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --><compress_data>1</compress_data> <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_tags>1</compress_tags> <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_threshold>20480</compress_threshold> <!-- Strings below this size will not be compressed --><compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf, lz4 (as l4z) and snappy --><use_lua>0</use_lua> <!-- Set to 1 if Lua scripts should be used for some operations --></backend_options></cache><!--session_save><![CDATA[files]]></session_save--><session_save>db</session_save><redis_session> <!-- All options seen here are the defaults --><host>127.0.0.1</host> <!-- Specify an absolute path if using a unix socket --><port>6379</port><password></password> <!-- Specify if your server requires authentication --><timeout>2.5</timeout> <!-- This is the connection timeout, not the locking timeout --><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><db>0</db> <!-- Redis database number; protection from accidental loss is improved by using a unique DB number for sessions --><compression_threshold>2048</compression_threshold> <!-- Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 --><compression_lib>gzip</compression_lib> <!-- gzip, lzf, lz4 or snappy --><log_level>1</log_level> <!-- 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) --><max_concurrency>6</max_concurrency> <!-- maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes --><break_after_frontend>5</break_after_frontend> <!-- seconds to wait for a session lock in the frontend; not as critical as admin --><fail_after>10</fail_after> <!-- seconds after which we bail from attempting to obtain lock (in addition to break after time) --><break_after_adminhtml>30</break_after_adminhtml><first_lifetime>600</first_lifetime> <!-- Lifetime of session for non-bots on the first write. 0 to disable --><bot_first_lifetime>60</bot_first_lifetime> <!-- Lifetime of session for bots on the first write. 0 to disable --><bot_lifetime>7200</bot_lifetime> <!-- Lifetime of session for bots on subsequent writes. 0 to disable --><disable_locking>0</disable_locking> <!-- Disable session locking entirely. --><min_lifetime>60</min_lifetime> <!-- Set the minimum session lifetime --><max_lifetime>2592000</max_lifetime> <!-- Set the maximum session lifetime --></redis_session></global><admin><routers><adminhtml><args><frontName><![CDATA[admin]]></frontName></args></adminhtml></routers></admin></config>
清除所有缓存和会话:
或者,以管理员身份登录到“管理”面板,
系统>缓存管理,
然后,点击“刷新Magento缓存”。
现在,重新启动为
要检查Redis服务器是否正常工作,请输入
如果结果是,
然后您的服务器正在响应。
您还可以通过以下方式监控所有流量:
然后刷新页面。如果您看到终端上生成的日志包含随机的字母数字字符,则表示缓存正在运行。
您还可以检查Redis服务器是否能够设置密钥,
您还可以使用“ info”命令来获取有关服务器的信息和统计信息,例如,