Skip to content

Commit 665ee4f

Browse files
committed
fix: close #313
1 parent a29345e commit 665ee4f

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

packages/core/src/core/db/redis/redis.ts

+22-18
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,30 @@ const start = async () => {
5454
* @returns Redis 客户端
5555
*/
5656
export const createRedis = async (): Promise<Client> => {
57-
const options = redis()
58-
let client = await create(options)
59-
if (client) {
60-
logger.info(`[redis] ${logger.green('Redis 连接成功')}`)
61-
return client as Client
62-
}
57+
try {
58+
const options = redis()
59+
let client = await create(options)
60+
if (client) {
61+
logger.info(`[redis] ${logger.green('Redis 连接成功')}`)
62+
return client as Client
63+
}
6364

64-
/** 第一次启动失败 */
65-
const result = await start()
66-
if (result) {
67-
logger.debug(logger.green('[redis] 主动拉起 Redis 成功'))
68-
client = await create(options)
69-
} else {
70-
logger.debug(logger.red('[redis] 主动拉起 Redis 失败'))
65+
/** 第一次启动失败 */
66+
const result = await start()
67+
if (result) {
68+
logger.debug(logger.green('[redis] 主动拉起 Redis 成功'))
69+
client = await create(options)
70+
} else {
71+
logger.debug(logger.red('[redis] 主动拉起 Redis 失败'))
72+
}
73+
if (client) return client as Client
74+
throw new Error('Redis 启动失败')
75+
} catch (error) {
76+
logger.debug(`[redis] ${logger.red('Redis 连接失败')}`)
77+
logger.debug(error)
78+
logger.debug(logger.yellow('[redis] 将降级为 redis-mock 实现'))
79+
return mock()
7180
}
72-
73-
if (client) return client as Client
74-
75-
logger.debug(logger.yellow('[redis] 将降级为 redis-mock 实现'))
76-
return mock()
7781
}
7882

7983
/**

0 commit comments

Comments
 (0)