fix(redis): redis命令控制台上下文隔离

This commit is contained in:
dalew
2026-06-16 18:02:25 +08:00
committed by GitHub
parent 2649005efd
commit c8385c16f2
@@ -816,38 +816,13 @@ function resumeRedisBrowserBackgroundWork() {
registerRedisDbFlushedListener();
}
async function loadPersistedRedisHistory() {
try {
const entries = await api.loadRedisHistory(200, 0);
if (entries.length === 0) return;
// Merge persisted entries into in-memory commandHistory (newest first, reversed for display order)
const persisted: RedisCommandHistoryEntry[] = entries.reverse().map((entry) => ({
id: ++commandHistoryId,
prompt: `db${entry.database}>`,
command: entry.sql,
output: entry.details_json ? formatRedisCommandResult(JSON.parse(entry.details_json)) : entry.error || "",
error: !entry.success,
}));
commandHistory.value = [...persisted, ...commandHistory.value];
scrollCommandTerminalToEnd();
} catch {
// Silently ignore load errors — history is best-effort
}
}
async function clearPersistedRedisHistory() {
try {
await api.clearRedisHistory();
toast(t("redis.historyCleared"));
} catch {
// Silently ignore
}
async function clearInMemoryHistory() {
commandHistory.value = [];
}
onMounted(() => {
resumeRedisBrowserBackgroundWork();
void loadKeys();
void loadPersistedRedisHistory();
});
onActivated(resumeRedisBrowserBackgroundWork);
@@ -976,7 +951,7 @@ defineExpose({ focusSearch });
{{ t("redis.pubsub") }}
</TabsTrigger>
</TabsList>
<Button v-if="activeSidePanel === 'command'" variant="ghost" size="icon" class="h-6 w-6" :title="t('redis.clearHistory')" @click="clearPersistedRedisHistory">
<Button v-if="activeSidePanel === 'command'" variant="ghost" size="icon" class="h-6 w-6" :title="t('redis.clearHistory')" @click="clearInMemoryHistory">
<History class="size-3.5" />
</Button>
</div>