diff --git a/packages/auth/src/redis/index.js b/packages/auth/src/redis/index.js index 4f2b5288ea..94b453c8f6 100644 --- a/packages/auth/src/redis/index.js +++ b/packages/auth/src/redis/index.js @@ -56,9 +56,13 @@ function init() { if (CLIENT) { CLIENT.disconnect() } - const { opts, host, port } = getRedisOptions(CLUSTERED) + + const { redisProtocolUrl, opts, host, port } = getRedisOptions(CLUSTERED) + if (CLUSTERED) { CLIENT = new Redis.Cluster([{ host, port }], opts) + } else if (redisProtocolUrl) { + CLIENT = new Redis(redisProtocolUrl) } else { CLIENT = new Redis(opts) } diff --git a/packages/auth/src/redis/utils.js b/packages/auth/src/redis/utils.js index 415dcbf463..8618cfe454 100644 --- a/packages/auth/src/redis/utils.js +++ b/packages/auth/src/redis/utils.js @@ -19,6 +19,14 @@ exports.SEPARATOR = SEPARATOR exports.getRedisOptions = (clustered = false) => { const [host, port] = REDIS_URL.split(":") + + let redisProtocolUrl + + // fully qualified redis URL + if (/rediss?/.test(host)) { + redisProtocolUrl = REDIS_URL + } + const opts = { connectTimeout: CONNECT_TIMEOUT_MS, } @@ -33,7 +41,7 @@ exports.getRedisOptions = (clustered = false) => { opts.port = port opts.password = REDIS_PASSWORD } - return { opts, host, port } + return { opts, host, port, redisProtocolUrl } } exports.addDbPrefix = (db, key) => {