]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/redis.ts
category parma -> categoryOneOf (videos list)
[github/Chocobozzz/PeerTube.git] / server / lib / redis.ts
index 5bd55109c7b7c05065a9dfca1228b05752f15aff..06a34006012f5e0e6ae96a2e56ff23e16d1af5f9 100644 (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)
 
@@ -78,16 +84,6 @@ class Redis {
     return this.setObject(this.buildCachedRouteKey(req), cached, lifetime)
   }
 
-  listJobs (jobsPrefix: string, state: string, mode: 'alpha', order: 'ASC' | 'DESC', offset: number, count: number) {
-    return new Promise<string[]>((res, rej) => {
-      this.client.sort(jobsPrefix + ':jobs:' + state, 'by', mode, order, 'LIMIT', offset.toString(), count.toString(), (err, values) => {
-        if (err) return rej(err)
-
-        return res(values)
-      })
-    })
-  }
-
   generateResetPasswordKey (userId: number) {
     return 'reset-password-' + userId
   }