Magento2 ElastiCache Redis Setup Crashes – Troubleshooting Guide

awsmagento2redis

I have Magento 2.4.3-p1 running on an EC2 Instance. I tried to configure ElastiCache Redis to it. I set up the service and followed the steps in Magento documentation to enable it. However, when I entered the following command using my host and port, Magento crashed:

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=<ElastiCache Primary Endpoint host>  --cache-backend-redis-port=<ElastiCache Primary Endpoint port> --cache-backend-redis-db=0

After calling the command I got the following message:

We saved default values for these options: remote-storage-prefix, remote-storage-key, remote-storage-secret, amqp-host, amqp-port, amqp-user, amqp-password, amqp-virtualhost, amqp-ssl, amqp-ssl-options, db-ssl-key, db-ssl-cert, db-ssl-ca, db-ssl-verify, allow-parallel-generation.

It felt like a success message, but When I tried to open my e-commerce storefront and the admin panel, I got HTTP Error 500. And when I tried to run any Magento command I got the following message:

MOVED 12337 {someIPAddress}:{RedisPort}

I double-checked that the issue comes from the Redis configuration by commenting it in app\etc\env.php and everything worked normally. Also, I checked all of the log files in var\log\ directory and none of them indicated any ERROR except in magento.cron.log which had the previous message printed several times.

Is it a bug in Magento2? And if so, does anyone have a workaround to fix it?

Best Answer

I got the problem fixed after trying different Redis settings in AWS. The configuration which worked for me is as follows:

  • Not using cluster mode.
  • 0 Replicas.
  • Using the same availability zone as the EC2 instance.

I am not sure whether other settings are valid nor the real bug in Magento which caused Redis to show the previous message, but the issue is worthing investigation from the Magento development team since it crashes everything and no clear output shows where does it come from.

Related Topic