fix: DbSelector 数据库 key 数量使用 INFO keyspace 直接获取
- 改用 INFO keyspace 命令替代解析完整 INFO 输出,避免正则匹配 Keyspace 段失败 - activeId 变化时重新获取 DB 数量和 key 计数 - expose refreshDbCounts 方法供父组件调用
This commit is contained in:
@@ -90,16 +90,16 @@ async function fetchDbInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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<number, number> = {}
|
const keyspace: Record<number, number> = {}
|
||||||
const match = info.match(/# Keyspace[\s\S]*?(?=\n#|$)/)
|
const lines = String(info).split('\n')
|
||||||
if (match) {
|
for (const line of lines) {
|
||||||
const lines = match[0].split('\n')
|
const dbMatch = line.match(/^db(\d+):keys=(\d+)/)
|
||||||
for (const line of lines) {
|
if (dbMatch) {
|
||||||
const dbMatch = line.match(/^db(\d+):keys=(\d+)/)
|
keyspace[parseInt(dbMatch[1], 10)] = parseInt(dbMatch[2], 10)
|
||||||
if (dbMatch) {
|
|
||||||
keyspace[parseInt(dbMatch[1], 10)] = parseInt(dbMatch[2], 10)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < dbCount.value; i++) {
|
for (let i = 0; i < dbCount.value; i++) {
|
||||||
@@ -127,8 +127,13 @@ watch(
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => connStore.activeId,
|
() => connStore.activeId,
|
||||||
() => {
|
async () => {
|
||||||
loadCustomNames()
|
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`
|
if (n >= 10000) return `${(n / 1000).toFixed(0)}k`
|
||||||
return String(n)
|
return String(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineExpose({ refreshDbCounts: fetchDbInfo })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user