diff --git a/config/index.js b/config/index.js index 897be84..949a669 100644 --- a/config/index.js +++ b/config/index.js @@ -11,6 +11,7 @@ const server_bind_address = process.env.BIND_ADDRESS || '127.0.0.1'; const redis_host = process.env.REDIS_HOST || '127.0.0.1'; const redis_port = parseInt(process.env.REDIS_PORT, 10) || 6379; const redis_password = process.env.REDIS_PASSWORD || ''; +const redis_tls = ["true", "1"].includes((process.env.REDIS_TLS || '').toLowerCase()); // Crash handler process.on('uncaughtException', (err) => { @@ -26,4 +27,5 @@ exports = module.exports = { redis_host, redis_port, redis_password, + redis_tls, }; diff --git a/util/redis.js b/util/redis.js index a24701e..541dda9 100644 --- a/util/redis.js +++ b/util/redis.js @@ -12,10 +12,16 @@ exports = module.exports = { redisPort: config.redis_port, redisPassword: config.redis_password, getRedis: (callback) => { + /* ioredis uses tls.connect() if the tls option is set, and passes it as + * additional options to tls.connect(). + */ + let tls = config.redis_tls ? {} : undefined; + const redis = new Redis({ host: config.redis_host, port: config.redis_port, password: config.redis_password, + tls, reconnectOnError(err) { /* Reconnect when ElastiCache has promoted some other node to primary & * demoted the node we are connected to a replica.