X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fredis.ts;h=941f7d5574021b5f91b38bc3034276d13fbab30a;hb=a031ab0b9b2f06969f074622383a5c974666ba93;hp=78b28986a0b4955f65286f90231fdf1b2156132f;hpb=94831479f5facff9469540a3d49dd347b88bdf5a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/redis.ts b/server/lib/redis.ts index 78b28986a..941f7d557 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -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) @@ -69,11 +75,12 @@ class Redis { } setCachedRoute (req: express.Request, body: any, lifetime: number, contentType?: string, statusCode?: number) { - const cached: CachedRoute = { - body: body.toString(), - contentType, - statusCode: statusCode.toString() - } + const cached: CachedRoute = Object.assign({}, { + body: body.toString() + }, + (contentType) ? { contentType } : null, + (statusCode) ? { statusCode: statusCode.toString() } : null + ) return this.setObject(this.buildCachedRouteKey(req), cached, lifetime) }