diff options
Diffstat (limited to 'server/lib/redis.ts')
-rw-r--r-- | server/lib/redis.ts | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts index 3628c0583..f77d0b62c 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts | |||
@@ -3,12 +3,13 @@ import { createClient, RedisClient } from 'redis' | |||
3 | import { logger } from '../helpers/logger' | 3 | import { logger } from '../helpers/logger' |
4 | import { generateRandomString } from '../helpers/utils' | 4 | import { generateRandomString } from '../helpers/utils' |
5 | import { | 5 | import { |
6 | CONFIG, | ||
7 | CONTACT_FORM_LIFETIME, | 6 | CONTACT_FORM_LIFETIME, |
8 | USER_EMAIL_VERIFY_LIFETIME, | 7 | USER_EMAIL_VERIFY_LIFETIME, |
9 | USER_PASSWORD_RESET_LIFETIME, | 8 | USER_PASSWORD_RESET_LIFETIME, |
10 | VIDEO_VIEW_LIFETIME | 9 | VIDEO_VIEW_LIFETIME, |
11 | } from '../initializers' | 10 | WEBSERVER |
11 | } from '../initializers/constants' | ||
12 | import { CONFIG } from '../initializers/config' | ||
12 | 13 | ||
13 | type CachedRoute = { | 14 | type CachedRoute = { |
14 | body: string, | 15 | body: string, |
@@ -30,7 +31,7 @@ class Redis { | |||
30 | if (this.initialized === true) return | 31 | if (this.initialized === true) return |
31 | this.initialized = true | 32 | this.initialized = true |
32 | 33 | ||
33 | this.client = createClient(Redis.getRedisClient()) | 34 | this.client = createClient(Redis.getRedisClientOptions()) |
34 | 35 | ||
35 | this.client.on('error', err => { | 36 | this.client.on('error', err => { |
36 | logger.error('Error in Redis client.', { err }) | 37 | logger.error('Error in Redis client.', { err }) |
@@ -41,10 +42,10 @@ class Redis { | |||
41 | this.client.auth(CONFIG.REDIS.AUTH) | 42 | this.client.auth(CONFIG.REDIS.AUTH) |
42 | } | 43 | } |
43 | 44 | ||
44 | this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' | 45 | this.prefix = 'redis-' + WEBSERVER.HOST + '-' |
45 | } | 46 | } |
46 | 47 | ||
47 | static getRedisClient () { | 48 | static getRedisClientOptions () { |
48 | return Object.assign({}, | 49 | return Object.assign({}, |
49 | (CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {}, | 50 | (CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {}, |
50 | (CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {}, | 51 | (CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {}, |
@@ -54,6 +55,14 @@ class Redis { | |||
54 | ) | 55 | ) |
55 | } | 56 | } |
56 | 57 | ||
58 | getClient () { | ||
59 | return this.client | ||
60 | } | ||
61 | |||
62 | getPrefix () { | ||
63 | return this.prefix | ||
64 | } | ||
65 | |||
57 | /************* Forgot password *************/ | 66 | /************* Forgot password *************/ |
58 | 67 | ||
59 | async setResetPasswordVerificationString (userId: number) { | 68 | async setResetPasswordVerificationString (userId: number) { |
@@ -88,7 +97,7 @@ class Redis { | |||
88 | return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) | 97 | return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) |
89 | } | 98 | } |
90 | 99 | ||
91 | async isContactFormIpExists (ip: string) { | 100 | async doesContactFormIpExist (ip: string) { |
92 | return this.exists(this.generateContactFormKey(ip)) | 101 | return this.exists(this.generateContactFormKey(ip)) |
93 | } | 102 | } |
94 | 103 | ||
@@ -98,7 +107,7 @@ class Redis { | |||
98 | return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME) | 107 | return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME) |
99 | } | 108 | } |
100 | 109 | ||
101 | async isVideoIPViewExists (ip: string, videoUUID: string) { | 110 | async doesVideoIPViewExist (ip: string, videoUUID: string) { |
102 | return this.exists(this.generateViewKey(ip, videoUUID)) | 111 | return this.exists(this.generateViewKey(ip, videoUUID)) |
103 | } | 112 | } |
104 | 113 | ||