Removing old redisProtocol string - it is causing confusion and should not be necessary.
This commit is contained in:
parent
86f7bd192f
commit
f8f1ec4ce9
|
@ -6,7 +6,6 @@ import BullQueue, { QueueOptions } from "bull"
|
||||||
import { addListeners, StalledFn } from "./listeners"
|
import { addListeners, StalledFn } from "./listeners"
|
||||||
import { Duration } from "../utils"
|
import { Duration } from "../utils"
|
||||||
import * as timers from "../timers"
|
import * as timers from "../timers"
|
||||||
import * as Redis from "ioredis"
|
|
||||||
|
|
||||||
// the queue lock is held for 5 minutes
|
// the queue lock is held for 5 minutes
|
||||||
const QUEUE_LOCK_MS = Duration.fromMinutes(5).toMs()
|
const QUEUE_LOCK_MS = Duration.fromMinutes(5).toMs()
|
||||||
|
@ -27,9 +26,9 @@ export function createQueue<T>(
|
||||||
jobQueue: JobQueue,
|
jobQueue: JobQueue,
|
||||||
opts: { removeStalledCb?: StalledFn } = {}
|
opts: { removeStalledCb?: StalledFn } = {}
|
||||||
): BullQueue.Queue<T> {
|
): BullQueue.Queue<T> {
|
||||||
const { opts: redisOpts, redisProtocolUrl } = getRedisOptions()
|
const { opts: redisOpts } = getRedisOptions()
|
||||||
const queueConfig: QueueOptions = {
|
const queueConfig: QueueOptions = {
|
||||||
redis: redisProtocolUrl! || (redisOpts as Redis.RedisOptions),
|
redis: redisOpts,
|
||||||
settings: {
|
settings: {
|
||||||
maxStalledCount: 0,
|
maxStalledCount: 0,
|
||||||
lockDuration: QUEUE_LOCK_MS,
|
lockDuration: QUEUE_LOCK_MS,
|
||||||
|
|
|
@ -91,12 +91,10 @@ function init(selectDb = DEFAULT_SELECT_DB) {
|
||||||
if (client) {
|
if (client) {
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
}
|
}
|
||||||
const { redisProtocolUrl, opts, host, port } = getRedisOptions()
|
const { opts, host, port } = getRedisOptions()
|
||||||
|
|
||||||
if (CLUSTERED) {
|
if (CLUSTERED) {
|
||||||
client = new RedisCore.Cluster([{ host, port }], opts)
|
client = new RedisCore.Cluster([{ host, port }], opts)
|
||||||
} else if (redisProtocolUrl) {
|
|
||||||
client = new RedisCore(redisProtocolUrl)
|
|
||||||
} else {
|
} else {
|
||||||
client = new RedisCore(opts)
|
client = new RedisCore(opts)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
|
import * as Redis from "ioredis"
|
||||||
|
|
||||||
const SLOT_REFRESH_MS = 2000
|
const SLOT_REFRESH_MS = 2000
|
||||||
const CONNECT_TIMEOUT_MS = 10000
|
const CONNECT_TIMEOUT_MS = 10000
|
||||||
|
@ -74,28 +75,29 @@ export function getRedisOptions() {
|
||||||
}
|
}
|
||||||
const [host, port] = url.split(":")
|
const [host, port] = url.split(":")
|
||||||
|
|
||||||
let redisProtocolUrl
|
let redisOpts: Redis.RedisOptions = {
|
||||||
|
|
||||||
// fully qualified redis URL
|
|
||||||
if (/rediss?:\/\//.test(env.REDIS_URL)) {
|
|
||||||
redisProtocolUrl = env.REDIS_URL
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts: any = {
|
|
||||||
connectTimeout: CONNECT_TIMEOUT_MS,
|
connectTimeout: CONNECT_TIMEOUT_MS,
|
||||||
|
port: parseInt(port),
|
||||||
|
host,
|
||||||
|
password,
|
||||||
}
|
}
|
||||||
|
let opts: Redis.ClusterOptions | Redis.RedisOptions = redisOpts
|
||||||
if (env.REDIS_CLUSTERED) {
|
if (env.REDIS_CLUSTERED) {
|
||||||
opts.redisOptions = {}
|
opts = {
|
||||||
opts.redisOptions.tls = {}
|
connectTimeout: CONNECT_TIMEOUT_MS,
|
||||||
opts.redisOptions.password = password
|
redisOptions: {
|
||||||
opts.slotsRefreshTimeout = SLOT_REFRESH_MS
|
...redisOpts,
|
||||||
opts.dnsLookup = (address: string, callback: any) => callback(null, address)
|
tls: {},
|
||||||
} else {
|
},
|
||||||
opts.host = host
|
slotsRefreshTimeout: SLOT_REFRESH_MS,
|
||||||
opts.port = port
|
dnsLookup: (address: string, callback: any) => callback(null, address),
|
||||||
opts.password = password
|
} as Redis.ClusterOptions
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
opts,
|
||||||
|
host,
|
||||||
|
port: parseInt(port),
|
||||||
}
|
}
|
||||||
return { opts, host, port: parseInt(port), redisProtocolUrl }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addDbPrefix(db: string, key: string) {
|
export function addDbPrefix(db: string, key: string) {
|
||||||
|
|
Loading…
Reference in New Issue