magento二次開發(fā) - 在magento中配置使用redis緩存

php常用的緩存工具:memcached和redis,本文講的是在magento框架中借助magento的模塊來使用redis

  • 準(zhǔn)備工作
  • magento中配置redis
  • 可能遇到的問題

準(zhǔn)備工作

確保你的電腦安裝并啟動(dòng)了redis服務(wù)、配置了php的redis擴(kuò)展
若沒有,查看此文《mac下安裝配置redis》

magento配置reids

  1. 確保magento框架中安裝并啟用了Cm_Cache_Backend_Redis模塊

  2. 修改以下路徑中的local配置文件
    項(xiàng)目根目錄/app/etc/local.xml
    config/global下添加子節(jié)點(diǎn)cache如下

<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 Redis 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>
  1. 清空magento緩存使得配置文件生效,關(guān)于如何清空magento緩存,參考《magento二次開發(fā) - 如何清除magento緩存》

可能遇到的問題

6.22:
今天上午打開本地網(wǎng)站時(shí)報(bào)如下錯(cuò)誤connection to Redis failed

錯(cuò)誤頁面

發(fā)現(xiàn)是因?yàn)閞edis服務(wù)沒有開啟導(dǎo)致的,開啟redis即可

說明magento在配置了redis之后那么要保持reids服務(wù)一直處于開啟狀態(tài)

參考:
[1]在magento中配置redis文檔:

http://devdocs.magento.com/guides/m1x/ce18-ee113/using_redis.html

[2]Cm_Cache_Backend_Redis配置

https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/blob/master/README.md

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容