aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/redis.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/redis.ts')
-rw-r--r--server/lib/redis.ts24
1 files changed, 20 insertions, 4 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 3706d2228..8430b2227 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -32,7 +32,8 @@ class Redis {
32 if (this.initialized === true) return 32 if (this.initialized === true) return
33 this.initialized = true 33 this.initialized = true
34 34
35 logger.info('Connecting to redis...') 35 const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
36 logger.info('Connecting to redis ' + redisMode + '...')
36 37
37 this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true })) 38 this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }))
38 this.client.on('error', err => logger.error('Redis failed to connect', { err })) 39 this.client.on('error', err => logger.error('Redis failed to connect', { err }))
@@ -56,10 +57,25 @@ class Redis {
56 this.prefix = 'redis-' + WEBSERVER.HOST + '-' 57 this.prefix = 'redis-' + WEBSERVER.HOST + '-'
57 } 58 }
58 59
59 static getRedisClientOptions (connectionName?: string, options: RedisOptions = {}): RedisOptions { 60 static getRedisClientOptions (name?: string, options: RedisOptions = {}): RedisOptions {
61 const connectionName = [ 'PeerTube', name ].join('')
62 const connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
63
64 if (CONFIG.REDIS.SENTINEL.ENABLED) {
65 return {
66 connectionName,
67 connectTimeout,
68 enableTLSForSentinelMode: CONFIG.REDIS.SENTINEL.ENABLE_TLS,
69 sentinelPassword: CONFIG.REDIS.AUTH,
70 sentinels: CONFIG.REDIS.SENTINEL.SENTINELS,
71 name: CONFIG.REDIS.SENTINEL.MASTER_NAME,
72 ...options
73 }
74 }
75
60 return { 76 return {
61 connectionName: [ 'PeerTube', connectionName ].join(''), 77 connectionName,
62 connectTimeout: 20000, // Could be slow since node use sync call to compile PeerTube 78 connectTimeout,
63 password: CONFIG.REDIS.AUTH, 79 password: CONFIG.REDIS.AUTH,
64 db: CONFIG.REDIS.DB, 80 db: CONFIG.REDIS.DB,
65 host: CONFIG.REDIS.HOSTNAME, 81 host: CONFIG.REDIS.HOSTNAME,