2018-02-27 12:16:17 +00:00
|
|
|
let host = process.env.REDIS_HOST || '127.0.0.1'
|
|
|
|
let port = process.env.REDIS_PORT || 6379
|
|
|
|
let db = process.env.REDIS_DB || 0
|
|
|
|
let password = process.env.REDIS_PASSWORD || null
|
|
|
|
const maxBackoff = 1000
|
|
|
|
|
|
|
|
if (process.env.REDIS_URL) {
|
|
|
|
password = process.env.REDIS_URL.match(/redis:\/\/.*:(.*)@.*:\d*$/i)[1]
|
|
|
|
host = process.env.REDIS_URL.match(/redis:\/\/.*:.*@(.*):\d*$/i)[1]
|
|
|
|
port = parseInt(process.env.REDIS_URL.match(/redis:\/\/.*:.*@.*:(\d*)$/i)[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
exports['default'] = {
|
2018-12-17 16:34:32 +00:00
|
|
|
redis: api => {
|
2018-02-27 12:16:17 +00:00
|
|
|
// konstructor: The redis client constructor method. All redis methods must be promises
|
|
|
|
// args: The arguments to pass to the constructor
|
|
|
|
// buildNew: is it `new konstructor()` or just `konstructor()`?
|
|
|
|
|
|
|
|
function retryStrategy (times) {
|
|
|
|
if (times === 1) {
|
2018-12-17 16:34:32 +00:00
|
|
|
const error =
|
|
|
|
'Unable to connect to Redis - please check your Redis config!'
|
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
|
|
console.error(error)
|
|
|
|
} else {
|
|
|
|
api.log(error, 'error')
|
|
|
|
}
|
2018-02-27 12:16:17 +00:00
|
|
|
return 5000
|
|
|
|
}
|
|
|
|
return Math.min(times * 50, maxBackoff)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
enabled: true,
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
_toExpand: false,
|
2018-02-27 12:16:17 +00:00
|
|
|
client: {
|
|
|
|
konstructor: require('ioredis'),
|
2018-12-17 16:34:32 +00:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
port: port,
|
|
|
|
host: host,
|
|
|
|
password: password,
|
|
|
|
db: db,
|
|
|
|
retryStrategy: retryStrategy
|
|
|
|
}
|
|
|
|
],
|
2018-02-27 12:16:17 +00:00
|
|
|
buildNew: true
|
|
|
|
},
|
|
|
|
subscriber: {
|
|
|
|
konstructor: require('ioredis'),
|
2018-12-17 16:34:32 +00:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
port: port,
|
|
|
|
host: host,
|
|
|
|
password: password,
|
|
|
|
db: db,
|
|
|
|
retryStrategy: retryStrategy
|
|
|
|
}
|
|
|
|
],
|
2018-02-27 12:16:17 +00:00
|
|
|
buildNew: true
|
|
|
|
},
|
|
|
|
tasks: {
|
|
|
|
konstructor: require('ioredis'),
|
2018-12-17 16:34:32 +00:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
port: port,
|
|
|
|
host: host,
|
|
|
|
password: password,
|
|
|
|
db: db,
|
|
|
|
retryStrategy: retryStrategy
|
|
|
|
}
|
|
|
|
],
|
2018-02-27 12:16:17 +00:00
|
|
|
buildNew: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|