Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Elasticache Redis Cluster MOVED Redirect fails #4

Open
neonexus opened this issue Dec 13, 2016 · 3 comments
Open

AWS Elasticache Redis Cluster MOVED Redirect fails #4

neonexus opened this issue Dec 13, 2016 · 3 comments

Comments

@neonexus
Copy link

When using AWS's Elasticache Redis Cluster (has built-in failover / replication / load balancing, no need to know the server addresses), occasionally Elasticache has to move data around, so it issues a MOVED Redirect, but this causes the adapter to fail, so Sails falls flat on it's face during lift. This is the console output I get when attempting to lift the app:

warn:  --minUptime not set. Defaulting to: 1000ms
warn:  --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
A hook (`orm`) failed to load!
{ Error
    at ReplyParser._parseResult (/var/www/backend/node_modules/ioredis/lib/parsers/javascript.js:39:14)
    at ReplyParser.execute (/var/www/backend/node_modules/ioredis/lib/parsers/javascript.js:139:20)
    at Socket.<anonymous> (/var/www/backend/node_modules/ioredis/lib/redis/event_handler.js:94:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)
  name: 'ReplyError',
  message: 'MOVED 3216 172.31.31.43:6379',
  command: 
   { name: 'get',
     args: [ 'waterline:{activepeople}:_sequences:id' ] } }

As you can probably tell, I have a model called ActivePeople that uses the adapter; it tracks live usage of the app (and wether or not the app is in focus).

Please help!

@Salakar
Copy link
Member

Salakar commented Dec 14, 2016

@neonexus please make an issue on the ioredis repo, will take a look there.

@neonexus
Copy link
Author

@Salakar there's no need, I found the fix yesterday as I was leaving work. Ultimately, it would be good to make mention of this in the documentation.

Because AWS Elasticache Redis Clusters are designed to be used with a single endpoint address, I was configuring the connection with "host". Didn't realize I had to use "hosts: [{host: 'Elasticache CFG Endpoint'}]" to trigger the clustering options. Once I fixed the config, everything worked again.

@ghost
Copy link

ghost commented Jan 30, 2018

I was having trouble with this too so I'm posting my solution to connect to an AWS Redis (ElasticCache) cluster.

I had the most success using the ioredis package for connecting to Redis from a Node.js script on my EC2 instance.

I used the path that AWS calls the "Configuration Endpoint" for redisHost and redisPort .

My EC2 is behind a VPC, so I also made sure my inbound network connections allowed port 6379 as documented here.

This solution also fixed the MOVED error I would see when trying to set a value in Redis.

const Redis = require('ioredis');
var client = new Redis.Cluster([`//${redisHost}:${redisPort}`], {
  scaleReads: 'slave'
});
client.hget(key, id).then(data => {
    // manipulate data
});
client.hgetall(key).then(data=>{
    // manipulate data
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants