]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/redis.ts
Add plugin table migration table
[github/Chocobozzz/PeerTube.git] / server / lib / redis.ts
index 3628c0583e3006dc91f30ba60fb076285cfe5fa1..f77d0b62c20ba22d3a92c01da5e097b7b35cf8c1 100644 (file)
@@ -3,12 +3,13 @@ import { createClient, RedisClient } from 'redis'
 import { logger } from '../helpers/logger'
 import { generateRandomString } from '../helpers/utils'
 import {
-  CONFIG,
   CONTACT_FORM_LIFETIME,
   USER_EMAIL_VERIFY_LIFETIME,
   USER_PASSWORD_RESET_LIFETIME,
-  VIDEO_VIEW_LIFETIME
-} from '../initializers'
+  VIDEO_VIEW_LIFETIME,
+  WEBSERVER
+} from '../initializers/constants'
+import { CONFIG } from '../initializers/config'
 
 type CachedRoute = {
   body: string,
@@ -30,7 +31,7 @@ class Redis {
     if (this.initialized === true) return
     this.initialized = true
 
-    this.client = createClient(Redis.getRedisClient())
+    this.client = createClient(Redis.getRedisClientOptions())
 
     this.client.on('error', err => {
       logger.error('Error in Redis client.', { err })
@@ -41,10 +42,10 @@ class Redis {
       this.client.auth(CONFIG.REDIS.AUTH)
     }
 
-    this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-'
+    this.prefix = 'redis-' + WEBSERVER.HOST + '-'
   }
 
-  static getRedisClient () {
+  static getRedisClientOptions () {
     return Object.assign({},
       (CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {},
       (CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {},
@@ -54,6 +55,14 @@ class Redis {
     )
   }
 
+  getClient () {
+    return this.client
+  }
+
+  getPrefix () {
+    return this.prefix
+  }
+
   /************* Forgot password *************/
 
   async setResetPasswordVerificationString (userId: number) {
@@ -88,7 +97,7 @@ class Redis {
     return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME)
   }
 
-  async isContactFormIpExists (ip: string) {
+  async doesContactFormIpExist (ip: string) {
     return this.exists(this.generateContactFormKey(ip))
   }
 
@@ -98,7 +107,7 @@ class Redis {
     return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME)
   }
 
-  async isVideoIPViewExists (ip: string, videoUUID: string) {
+  async doesVideoIPViewExist (ip: string, videoUUID: string) {
     return this.exists(this.generateViewKey(ip, videoUUID))
   }