1
0
Fork 0

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

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

View file

@ -23,6 +23,8 @@ database:
password: 'peertube' password: 'peertube'
# Redis server for short time storage # 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: redis:
hostname: 'localhost' hostname: 'localhost'
port: 6379 port: 6379

View file

@ -44,7 +44,6 @@ function checkMissedConfig () {
'webserver.https', 'webserver.hostname', 'webserver.port', 'webserver.https', 'webserver.hostname', 'webserver.port',
'trust_proxy', 'trust_proxy',
'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', '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', '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', 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache',
'log.level', 'log.level',
@ -56,6 +55,12 @@ function checkMissedConfig () {
'instance.default_nsfw_policy', 'instance.robots', 'instance.default_nsfw_policy', 'instance.robots',
'services.twitter.username', 'services.twitter.whitelisted' 'services.twitter.username', 'services.twitter.whitelisted'
] ]
const requiredAlternatives = [
[ // set
['redis.hostname', 'redis.port'], // alternative
['redis.socket']
]
]
const miss: string[] = [] const miss: string[] = []
for (const key of required) { 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 return miss
} }

View file

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

View file

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

View file

@ -24,11 +24,7 @@ class Redis {
if (this.initialized === true) return if (this.initialized === true) return
this.initialized = true this.initialized = true
this.client = createClient({ this.client = createClient(Redis.getRedisClient())
host: CONFIG.REDIS.HOSTNAME,
port: CONFIG.REDIS.PORT,
db: CONFIG.REDIS.DB
})
this.client.on('error', err => { this.client.on('error', err => {
logger.error('Error in Redis client.', { err }) logger.error('Error in Redis client.', { err })
@ -42,6 +38,16 @@ class Redis {
this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' 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) { async setResetPasswordVerificationString (userId: number) {
const generatedString = await generateRandomString(32) const generatedString = await generateRandomString(32)