Search code examples
amazon-web-servicesredisamazon-elasticache

AWS Elasticache for Redis: How to fix the error TYPE returned an error: MOVED or Error: MOVED


I have a AWS Elasticache for Redis configured with cluster mode enabled, using multi az and with 5 shards and 3 nodes (1 primary and 2 replicas).

From an EC2 instance running the latest Amazon Linux 2023, i have installed the redis-cli tool.

I'm trying to collect data for bigkeys and hotkeys, but for each redis-cli run, i get different results (both errors):

~> redis6-cli -c -h myinstance.cache.com -p 6379 --tls --hotkeys

# Scanning the entire keyspace to find hot keys as well as
# average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).

Error: MOVED 6787 node.myinstance.cache.com:6379
~> redis6-cli -c -h myinstance.cache.com -p 6379 --tls --bigkeys

# Scanning the entire keyspace to find hot keys as well as
# average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).

TYPE returned an error: MOVED 6787 node.myinstance.cache.com:6379

I did a lot of research on the errors above and all i can find is that you should use the -c command line switch to enable redis-cli to follow the MOVED errors/messages, but as can be seen, I'm using it.

The REPL works just fine for get, set and delete keys. I tried to use --scan parameter and it also worked.


Solution

  • It seems to be a redis-cli issue, see https://github.com/redis/redis/issues/4810.

    The following workaround can be used:

    1. Using redis-cli connect to the cluster configuration endpoint
    2. Find the primary nodes by executing cluster nodes: redis6-cli -h configurationendpoint.cache.com -p 6379 --tls cluster nodes
    3. Run the bigkeys and hotkeys against the node endpoint of individual primary nodes: redis6-cli -c -h myinstance.001.cache.com -p 6379 --tls --bigkeys

    Also, you can use redis-cli 'check' command to find out if there are multiple slot owners: redis6-cli --tls --cluster check configurationendpoint.cache.com:6379 --cluster-search-multiple-owners. If there are any, you can contact ElastiCache support to see if the cluster topology needs to be fixed.