debug: 添加连接日志

This commit is contained in:
2026-07-04 20:06:43 +08:00
parent 88dfedc544
commit d488612c27
2 changed files with 8 additions and 2 deletions
+3 -1
View File
@@ -70,10 +70,12 @@ export function registerIpcHandlers(): void {
// Redis
ipcMain.handle('redis:connect', async (_e, id: string, opts) => {
try {
console.log(`[IPC] redis:connect id=${id}`, opts)
await redisService.connect(id, opts)
return { success: true }
} catch (err: any) {
return { success: false, error: err.message }
console.error(`[IPC] redis:connect error:`, err.message)
return { success: false, error: err.message || String(err) }
}
})
ipcMain.handle('redis:disconnect', async (_e, id: string) => {
+5 -1
View File
@@ -53,14 +53,17 @@ export async function connect(id: string, opts: ConnectionOptions): Promise<void
}
return new Promise((resolve, reject) => {
console.log(`[Redis] Connecting to ${opts.host}:${opts.port}...`)
const redis = new Redis(buildRedisOptions(opts))
redis.once('ready', () => {
console.log(`[Redis] Connected to ${opts.host}:${opts.port}`)
clients.set(id, redis)
resolve()
})
redis.once('error', (err: Error) => {
console.error(`[Redis] Connection error:`, err.message)
redis.disconnect()
reject(err)
})
@@ -68,8 +71,9 @@ export async function connect(id: string, opts: ConnectionOptions): Promise<void
// Timeout
setTimeout(() => {
if (!clients.has(id)) {
console.error(`[Redis] Connection timeout`)
redis.disconnect()
reject(new Error('Connection timeout'))
reject(new Error('连接超时,请检查主机和端口'))
}
}, 12000)
})