Skip to content

Commit e39ee68

Browse files
committed
fix: config redis
1 parent 33b563b commit e39ee68

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/config/redis.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import redis from 'redis'
1+
import { isEmpty } from 'lodash'
2+
import redis, { ClientOpts } from 'redis'
23

34
require('dotenv').config()
45

56
const { REDIS_HOST, REDIS_PORT, REDIS_PASSWORD } = process.env
67

7-
const client = redis.createClient({
8+
const optionConfigs: ClientOpts = {
89
host: REDIS_HOST,
910
port: Number(REDIS_PORT),
10-
password: REDIS_PASSWORD,
11-
})
11+
}
12+
13+
if (!isEmpty(REDIS_PASSWORD)) {
14+
optionConfigs.password = REDIS_PASSWORD
15+
}
16+
17+
const client = redis.createClient(optionConfigs)
1218

1319
client.on('connect', function () {
1420
console.log('Redis client connected')

0 commit comments

Comments
 (0)