1
0
Fork 0
mirror of synced 2024-10-02 01:56:57 +13:00

publishing redis client fix to master

This commit is contained in:
Martin McKeaveney 2021-09-13 18:29:44 +01:00
parent 08c3bd467b
commit 02c9719b03
2 changed files with 14 additions and 3 deletions

View file

@ -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)
}

View file

@ -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) => {