Add redis tls and cert

This commit is contained in:
Hongbo Wu
2022-09-22 11:17:02 +08:00
parent 97ffef34bf
commit f4f99a30b2
2 changed files with 14 additions and 3 deletions

View File

@ -181,7 +181,10 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
const ssml = `${startSsml(ssmlOptions)}${utteranceInput.text}${endSsml()}`
// hash ssml to get the cache key
const cacheKey = crypto.createHash('md5').update(ssml).digest('hex')
const redisClient = await createRedisClient()
const redisClient = await createRedisClient(
process.env.REDIS_URL,
process.env.REDIS_CERT
)
// find audio data in cache
const cacheResult = await redisClient.get(cacheKey)
if (cacheResult) {

View File

@ -1,11 +1,19 @@
import { createClient } from 'redis'
export const createRedisClient = async () => {
const redisClient = createClient({ url: process.env.REDIS_URL })
export const createRedisClient = async (url?: string, cert?: string) => {
const redisClient = createClient({
url,
socket: {
tls: url?.startsWith('rediss://'),
cert: cert?.replace(/\\n/g, '\n'),
rejectUnauthorized: false,
},
})
redisClient.on('error', (err) => console.error('Redis Client Error', err))
await redisClient.connect()
console.log('Redis Client Connected:', url)
return redisClient
}