adding redis unix connection

This commit is contained in:
Rigel Kent
2018-05-14 17:51:15 +02:00
committed by Rigel Kent
parent 4503cb2a89
commit 19f7b248d8
6 changed files with 36 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import * as Bull from 'bull'
import { JobState, JobType } from '../../../shared/models'
import { logger } from '../../helpers/logger'
import { Redis } from '../redis'
import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_REQUEST_TTL } from '../../initializers'
import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast'
import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
@@ -63,12 +64,7 @@ class JobQueue {
this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOST
const queueOptions = {
prefix: this.jobRedisPrefix,
redis: {
host: CONFIG.REDIS.HOSTNAME,
port: CONFIG.REDIS.PORT,
auth: CONFIG.REDIS.AUTH,
db: CONFIG.REDIS.DB
}
redis: Redis.getRedisClient()
}
for (const handlerName of Object.keys(handlers)) {

View File

@@ -24,11 +24,7 @@ class Redis {
if (this.initialized === true) return
this.initialized = true
this.client = createClient({
host: CONFIG.REDIS.HOSTNAME,
port: CONFIG.REDIS.PORT,
db: CONFIG.REDIS.DB
})
this.client = createClient(Redis.getRedisClient())
this.client.on('error', err => {
logger.error('Error in Redis client.', { err })
@@ -42,6 +38,16 @@ class Redis {
this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-'
}
static getRedisClient () {
return Object.assign({},
(CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {},
(CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {},
(CONFIG.REDIS.HOSTNAME && CONFIG.REDIS.PORT) ?
{ host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT } :
{ path: CONFIG.REDIS.SOCKET }
)
}
async setResetPasswordVerificationString (userId: number) {
const generatedString = await generateRandomString(32)