From b4aab761414eea857772837ae7f5cca909d52766 Mon Sep 17 00:00:00 2001 From: Jokul Date: Sat, 11 Jul 2026 23:03:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20DbSelector=20=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=20key=20=E6=95=B0=E9=87=8F=E4=BD=BF=E7=94=A8=20INFO=20keyspace?= =?UTF-8?q?=20=E7=9B=B4=E6=8E=A5=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 改用 INFO keyspace 命令替代解析完整 INFO 输出,避免正则匹配 Keyspace 段失败 - activeId 变化时重新获取 DB 数量和 key 计数 - expose refreshDbCounts 方法供父组件调用 --- .../src/components/key/DbSelector.vue | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/components/key/DbSelector.vue b/src/renderer/src/components/key/DbSelector.vue index 0ce50dd..2cc4167 100644 --- a/src/renderer/src/components/key/DbSelector.vue +++ b/src/renderer/src/components/key/DbSelector.vue @@ -90,16 +90,16 @@ async function fetchDbInfo() { } try { - const info = await connStore.getInfo() + // Use INFO keyspace directly for reliable parsing + const info: any = await window.electronAPI.redis.execute( + connStore.activeId, 'INFO', ['keyspace'] + ) const keyspace: Record = {} - const match = info.match(/# Keyspace[\s\S]*?(?=\n#|$)/) - if (match) { - const lines = match[0].split('\n') - for (const line of lines) { - const dbMatch = line.match(/^db(\d+):keys=(\d+)/) - if (dbMatch) { - keyspace[parseInt(dbMatch[1], 10)] = parseInt(dbMatch[2], 10) - } + const lines = String(info).split('\n') + for (const line of lines) { + const dbMatch = line.match(/^db(\d+):keys=(\d+)/) + if (dbMatch) { + keyspace[parseInt(dbMatch[1], 10)] = parseInt(dbMatch[2], 10) } } for (let i = 0; i < dbCount.value; i++) { @@ -127,8 +127,13 @@ watch( watch( () => connStore.activeId, - () => { + async () => { loadCustomNames() + if (connStore.isConnected) { + selectedDb.value = 0 + keyStore.currentDb = 0 + await fetchDbInfo() + } } ) @@ -143,6 +148,8 @@ function formatCount(n: number): string { if (n >= 10000) return `${(n / 1000).toFixed(0)}k` return String(n) } + +defineExpose({ refreshDbCounts: fetchDbInfo })