1
votes

I just moved my Magento site to Amazon EC2, but keep getting "Connection to Redis failed after 2 failures" error. I've tried to remove the redis configuration from app/etc/local.xml but still get that error.

I also tried to disable all the cache options directly from core_cache_option table. I have no idea how to clean the already cached files. No cache files under var/cache folder as expected and I've tried to flushall from redis-cli command prompt, but still keep getting this error.

Any idea what else should I try?

<cache>
  <backend_options>
    <server><![CDATA[/var/tmp/_cache.sock]]></server>
    <port><![CDATA[0]]></port>
    <persistent><![CDATA[]]></persistent>
    <database><![CDATA[0]]></database>
    <password><![CDATA[]]></password>
    <connect_retries><![CDATA[1]]></connect_retries>
    <read_timeout><![CDATA[10]]></read_timeout>
    <automatic_cleaning_factor><![CDATA[0]]></automatic_cleaning_factor>
    <compress_data><![CDATA[1]]></compress_data>
    <compress_tags><![CDATA[1]]></compress_tags>
    <compress_threshold><![CDATA[20480]]></compress_threshold>
    <compression_lib><![CDATA[gzip]]></compression_lib>
    <use_lua><![CDATA[0]]></use_lua>
  </backend_options>
  <backend><![CDATA[Cm_Cache_Backend_Redis]]></backend>
</cache>
1

1 Answers

11
votes

Given EC2 instances are ephemeral, you should be able to regenerate the instance, right? If that's not an option —

First, Check app/etc/ for other XML files. Magento will parse any XML files it finds in this folder. I've seen something like the following trip people up

$ ls app/etc/*.xml
local.xml
local.backup.xml

Magento parses both local.xml and local.backup.xml, and the backup values override the new values in local.xml. Also, make sure you're working with the local.xml you think you are. Magento loads the local configuration in the following location. Add some temporary debugging to make sure it's doing what you think it's doing.

#File: app/code/core/Mage/Core/Model/Config.php
public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        var_dump($file);
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

Second, after you clear your cache, make sure Magento's reloading the configuration. Add some temporary debugging to

#File: app/code/core/Mage/Core/Model/Config.php
public function init($options=array())
{
    $this->setCacheChecksum(null);
    $this->_cacheLoadedSections = array();
    $this->setOptions($options);
    $this->loadBase();

    $cacheLoad = $this->loadModulesCache();
    if ($cacheLoad) {
        var_dump("Loaded Config from Cache");
        return $this;
    }
    else
    {
        var_dump("Reloading configuration");     
    }

    $this->loadModules();
    $this->loadDb();
    $this->saveCache();
    return $this;
}

Finally, if you suspect the problem is a file based cache not clearing, drop some debugging code in

#File: app/code/core/Mage/Core/Model/Config/Options.php
public function getCacheDir()
{
    //$dir = $this->getDataSetDefault('cache_dir', $this->getVarDir().DS.'cache');
    $dir = $this->_data['cache_dir'];
    $this->createDirIfNotExists($dir);
    var_dump($dir);
    return $dir;
}

This will let you know the cache directory Magento's reading from — if Magento can't read the local var, it'll pop up to the root level /var/ folder.