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 // Redis
ipcMain.handle('redis:connect', async (_e, id: string, opts) => { ipcMain.handle('redis:connect', async (_e, id: string, opts) => {
try { try {
console.log(`[IPC] redis:connect id=${id}`, opts)
await redisService.connect(id, opts) await redisService.connect(id, opts)
return { success: true } return { success: true }
} catch (err: any) { } 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) => { 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) => { return new Promise((resolve, reject) => {
console.log(`[Redis] Connecting to ${opts.host}:${opts.port}...`)
const redis = new Redis(buildRedisOptions(opts)) const redis = new Redis(buildRedisOptions(opts))
redis.once('ready', () => { redis.once('ready', () => {
console.log(`[Redis] Connected to ${opts.host}:${opts.port}`)
clients.set(id, redis) clients.set(id, redis)
resolve() resolve()
}) })
redis.once('error', (err: Error) => { redis.once('error', (err: Error) => {
console.error(`[Redis] Connection error:`, err.message)
redis.disconnect() redis.disconnect()
reject(err) reject(err)
}) })
@@ -68,8 +71,9 @@ export async function connect(id: string, opts: ConnectionOptions): Promise<void
// Timeout // Timeout
setTimeout(() => { setTimeout(() => {
if (!clients.has(id)) { if (!clients.has(id)) {
console.error(`[Redis] Connection timeout`)
redis.disconnect() redis.disconnect()
reject(new Error('Connection timeout')) reject(new Error('连接超时,请检查主机和端口'))
} }
}, 12000) }, 12000)
}) })