From 02c9719b03ab5d654d32d7829d7155d6f7b34fa9 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 13 Sep 2021 18:29:44 +0100 Subject: [PATCH] publishing redis client fix to master --- packages/auth/src/redis/index.js | 5 ++++- packages/auth/src/redis/utils.js | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/redis/index.js b/packages/auth/src/redis/index.js index 4f2b5288ea..48a24ad0bc 100644 --- a/packages/auth/src/redis/index.js +++ b/packages/auth/src/redis/index.js @@ -56,9 +56,12 @@ 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..09b4905298 100644 --- a/packages/auth/src/redis/utils.js +++ b/packages/auth/src/redis/utils.js @@ -18,7 +18,15 @@ exports.Databases = { exports.SEPARATOR = SEPARATOR exports.getRedisOptions = (clustered = false) => { - const [host, port] = REDIS_URL.split(":") + const [host, port, ...rest] = REDIS_URL.split(":") + + let redisProtocolUrl + + // fully qualified redis URL + if (rest.length && /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) => {