]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/redis.ts
Update credits
[github/Chocobozzz/PeerTube.git] / server / lib / redis.ts
index 1e7c0a8211ebe791b1a1e27cdca0f2e2d7e87407..5bd55109c7b7c05065a9dfca1228b05752f15aff 100644 (file)
@@ -2,7 +2,7 @@ import * as express from 'express'
 import { createClient, RedisClient } from 'redis'
 import { logger } from '../helpers/logger'
 import { generateRandomString } from '../helpers/utils'
-import { CONFIG, FEEDS, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers'
+import { CONFIG, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers'
 
 type CachedRoute = {
   body: string,
@@ -26,7 +26,8 @@ class Redis {
 
     this.client = createClient({
       host: CONFIG.REDIS.HOSTNAME,
-      port: CONFIG.REDIS.PORT
+      port: CONFIG.REDIS.PORT,
+      db: CONFIG.REDIS.DB
     })
 
     this.client.on('error', err => {
@@ -67,14 +68,14 @@ class Redis {
     return cached as CachedRoute
   }
 
-  setCachedRoute (req: express.Request, body: any, contentType?: string, statusCode?: number) {
+  setCachedRoute (req: express.Request, body: any, lifetime: number, contentType?: string, statusCode?: number) {
     const cached: CachedRoute = {
       body: body.toString(),
       contentType,
       statusCode: statusCode.toString()
     }
 
-    return this.setObject(this.buildCachedRouteKey(req), cached, FEEDS.CACHE_LIFETIME)
+    return this.setObject(this.buildCachedRouteKey(req), cached, lifetime)
   }
 
   listJobs (jobsPrefix: string, state: string, mode: 'alpha', order: 'ASC' | 'DESC', offset: number, count: number) {
@@ -87,6 +88,18 @@ class Redis {
     })
   }
 
+  generateResetPasswordKey (userId: number) {
+    return 'reset-password-' + userId
+  }
+
+  buildViewKey (ip: string, videoUUID: string) {
+    return videoUUID + '-' + ip
+  }
+
+  buildCachedRouteKey (req: express.Request) {
+    return req.method + '-' + req.originalUrl
+  }
+
   private getValue (key: string) {
     return new Promise<string>((res, rej) => {
       this.client.get(this.prefix + key, (err, value) => {
@@ -145,18 +158,6 @@ class Redis {
     })
   }
 
-  private generateResetPasswordKey (userId: number) {
-    return 'reset-password-' + userId
-  }
-
-  private buildViewKey (ip: string, videoUUID: string) {
-    return videoUUID + '-' + ip
-  }
-
-  private buildCachedRouteKey (req: express.Request) {
-    return req.method + '-' + req.originalUrl
-  }
-
   static get Instance () {
     return this.instance || (this.instance = new this())
   }