adding redis unix connection

pull/777/merge
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

@ -23,6 +23,8 @@ database:
username: 'peertube'
password: 'peertube'
# You can also specify a 'socket' path to a unix socket but first need to
# comment out hostname and port
redis:
hostname: 'localhost'
port: 6379

View File

@ -23,6 +23,8 @@ database:
password: 'peertube'
# Redis server for short time storage
# You can also specify a 'socket' path to a unix socket but first need to
# comment out hostname and port
redis:
hostname: 'localhost'
port: 6379
@ -124,4 +126,4 @@ services:
# If true, a video player will be embedded in the Twitter feed on PeerTube video share
# If false, we use an image link card that will redirect on your PeerTube instance
# Test on https://cards-dev.twitter.com/validator to see if you are whitelisted
whitelisted: false
whitelisted: false

View File

@ -44,7 +44,6 @@ function checkMissedConfig () {
'webserver.https', 'webserver.hostname', 'webserver.port',
'trust_proxy',
'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
'redis.hostname', 'redis.port', 'redis.auth', 'redis.db',
'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address',
'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache',
'log.level',
@ -56,6 +55,12 @@ function checkMissedConfig () {
'instance.default_nsfw_policy', 'instance.robots',
'services.twitter.username', 'services.twitter.whitelisted'
]
const requiredAlternatives = [
[ // set
['redis.hostname', 'redis.port'], // alternative
['redis.socket']
]
]
const miss: string[] = []
for (const key of required) {
@ -64,6 +69,13 @@ function checkMissedConfig () {
}
}
const missingAlternatives = requiredAlternatives.filter(
set => !set.find(alternative => !alternative.find(key => !config.has(key)))
)
missingAlternatives
.forEach(set => set[0].forEach(key => miss.push(key)))
return miss
}

View File

@ -116,10 +116,11 @@ const CONFIG = {
PASSWORD: config.get<string>('database.password')
},
REDIS: {
HOSTNAME: config.get<string>('redis.hostname'),
PORT: config.get<number>('redis.port'),
AUTH: config.get<string>('redis.auth'),
DB: config.get<number>('redis.db')
HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
DB: config.has('redis.db') ? config.get<number>('redis.db') : null
},
SMTP: {
HOSTNAME: config.get<string>('smtp.hostname'),

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)