Magento2配置redis缓存,包括redis保存session, cache page_cache
session redis配置
修改文件:app/etc/env.php session的节点改成下面的
'session' =>
array (
'save' => 'redis',
'redis' =>
array (
'host' => '127.0.0.1',
'port' => '6379',
'password' => '',
'timeout' => '2.5',
'persistent_identifier' => '',
'database' => '0',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '1',
'max_concurrency' => '6',
'break_after_frontend' => '5',
'break_after_adminhtml' => '30',
'first_lifetime' => '600',
'bot_first_lifetime' => '60',
'bot_lifetime' => '7200',
'disable_locking' => '0',
'min_lifetime' => '60',
'max_lifetime' => '2592000'
)
),
特别说明:Magento 2.0.6及后面的版本才支持 redis保存session 官网说明链接:http://devdocs.magento.com/guides/v2.0/config-guide/redis/redis-session.html
page cache redis配置
'cache' => array(
'frontend' => array(
'default' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array(
'server' => '127.0.0.1',
'port' => '6379',
'persistent' => 'mage2', // Specify a unique string like "cache-db0" to enable persistent connections.
'database' => '0',
'password' => '',
'force_standalone' => '0', // 0 for phpredis, 1 for standalone PHP
'connect_retries' => '1', // Reduces errors due to random connection failures
'read_timeout' => '10', // Set read timeout duration
'automatic_cleaning_factor' => '0', // Disabled by default
'compress_data' => '1', // 0-9 for compression level, recommended: 0 or 1
'compress_tags' => '1', // 0-9 for compression level, recommended: 0 or 1
'compress_threshold' => '20480', // Strings below this size will not be compressed
'compression_lib' => 'gzip', // Supports gzip, lzf and snappy,
'use_lua' => '0' // Lua scripts should be used for some operations
)
),
'page_cache' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array(
'server' => '127.0.0.1',
'port' => '6379',
'persistent' => 'mage2', // Specify a unique string like "cache-db0" to enable persistent connections.
'database' => '1', // Separate database 1 to keep FPC separately
'password' => '',
'force_standalone' => '0', // 0 for phpredis, 1 for standalone PHP
'connect_retries' => '1', // Reduces errors due to random connection failures
'lifetimelimit' => '57600', // 16 hours of lifetime for cache record
'compress_data' => '0' // DISABLE compression for EE FPC since it already uses compression
)
)
)
),
官网说明链接:http://devdocs.magento.com/guides/v2.0/config-guide/redis/redis-pg-cache.html
验证配置
验证配置成功与否,最简单的就是先清空magento2网站var目录下面的 session 和cache文件夹,然后再运行网站前台,网站没出错而且这2个文件夹下面也没有生成其他的文件 就已经配置成功了。 当然,你可以安装上面给出来的官网链接里面的方法检查。