Are you trying to connect to an AWS Elasticache Serverless Redis instance but it is just not happening? You have double checked your security groups, your subnets, and you are just not connecting? I was usingioredis to connect but it kept timing out as if it was blocked by a security group. After verifying that was not the case I turned on ioredis’s debug logging and saw it was indeed able to at least open a connection to redis but it was failing after that.
What it turned out to be was an issue with TLS and the solution was to turn off TLS when initializing the ioredis client. Since we have multiple other layers of security between the Security Groups and VPCs additional authentication for this project, the indexes for my daily writing, seemed unnecessary so I turned off the TLS and it worked.
Here is the code I am using to initialize the connection:
let _redis: Redis;
export const getRedis = (): Redis => {
if (!_redis) {
console.log("Connecting Redis:", process.env.REDIS_HOST)
let options: any = {
host: process.env.REDIS_HOST,
port: 6379,
// tls: {}
}
if (options.host !== '127.0.0.1') {
options.tls = {};
}
_redis = new Redis(options);
console.log("Redis Successful:", process.env.REDIS_HOST)
}
return _redis;
}
Note that when I develop locally I use a local Docker Compose file to boot up a local copy of redis. Therefore the localhost check.
Best of luck and feel free to ping me if you have questions.
~Cheers
PS: If you are interested in engaging my services as a Web Application Architect check out my Group Coaching Program or 1 on 1 Consulting at schematical.com and check out my FREE eBook 20 Things You Can DoTo Save Money On Your Amazon Web Services Bill Today
Signup for the mailing list