What
Connect ioredis to AWS ElastiCache Redis with proper TLS and reconnection handling.
Why
ElastiCache requires TLS (rediss://) and needs special handling for connection errors.
How
import Redis from "ioredis";
const redisClient = new Redis(process.env.REDIS_URL, {
lazyConnect: true,
connectTimeout: 15000,
retryStrategy: (times) => Math.min(times * 30, 1000),
reconnectOnError(err) {
// Retry on specific errors
return [/READONLY/, /ETIMEDOUT/].some((re) => re.test(err.message));
},
});