完善 redis 配置环境变量
This commit is contained in:
@@ -3,9 +3,13 @@ import { createClient, type RedisClientType } from 'redis'
|
||||
|
||||
const globalForRedis = globalThis as { redis?: RedisClientType }
|
||||
|
||||
const { REDIS_HOST, REDIS_PORT } = process.env
|
||||
const { REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD } = process.env
|
||||
if (!globalForRedis.redis) {
|
||||
globalForRedis.redis = createClient({ url: `redis://${REDIS_HOST}:${REDIS_PORT}` })
|
||||
const url = REDIS_USERNAME && REDIS_PASSWORD
|
||||
? `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}`
|
||||
: `redis://${REDIS_HOST}:${REDIS_PORT}`
|
||||
console.log('test url', url)
|
||||
globalForRedis.redis = createClient({ url })
|
||||
}
|
||||
|
||||
const redis = globalForRedis.redis
|
||||
|
||||
Reference in New Issue
Block a user