25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(redis): keep key list action bar and add metadata backfill
OkaneGai6c85bf552d11
diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.expiry.spec.ts b/apps/desktop/src/components/redis/RedisKeyBrowser.expiry.spec.tsindex 1ba72039ad..3ed176f8da 100644--- a/apps/desktop/src/components/redis/RedisKeyBrowser.expiry.spec.ts+++ b/apps/desktop/src/components/redis/RedisKeyBrowser.expiry.spec.ts@@ -2233,8 +2233,12 @@ describe("RedisKeyBrowser interrupted Fetch All", () => {await submitKeySearch("group:second");expect(document.querySelector(`[data-redis-leaf="${buffered.key_raw}"]`)).not.toBeNull();+ // The first footer click continues from the current cursor, so the sweep+ // costs the same round trip as before.expect(mocks.redisScanKeysBatch).toHaveBeenCalledTimes(2);- expect(document.body.textContent).not.toContain("redis.fetchAllKeys");+ // The sweep completed, so the action bar keeps offering the full reload+ // instead of disappearing together with the exhausted button.+ expect(document.body.textContent).toContain("redis.refetchAllKeys");});it("filters a completed Fetch All snapshot while editing a key search", async () => {diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.infiniteScroll.spec.ts b/apps/desktop/src/components/redis/RedisKeyBrowser.infiniteScroll.spec.tsindex 9eefe94006..4984d415c2 100644--- a/apps/desktop/src/components/redis/RedisKeyBrowser.infiniteScroll.spec.ts+++ b/apps/desktop/src/components/redis/RedisKeyBrowser.infiniteScroll.spec.ts@@ -15,6 +15,7 @@ const mocks = vi.hoisted(() => ({scrollerRefresh: vi.fn(),ensureConnected: vi.fn(),redisScanKeysBatch: vi.fn(),+ redisKeyMetadataBatch: vi.fn(),redisScanValues: vi.fn(),redisGetValue: vi.fn(),redisSetString: vi.fn(),@@ -46,6 +47,7 @@ const mocks = vi.hoisted(() => ({vi.mock("@/lib/backend/api", () => ({redisScanKeysBatch: mocks.redisScanKeysBatch,+ redisKeyMetadataBatch: mocks.redisKeyMetadataBatch,redisScanValues: mocks.redisScanValues,redisGetValue: mocks.redisGetValue,redisSetString: mocks.redisSetString,@@ -375,6 +377,7 @@ function resetApiMocks() {mocks.queryResultMaxRowsEnabled = true;mocks.queryResultMaxRows = 5000;mocks.redisScanKeysBatch.mockResolvedValue({ cursor: 0, keys: [], total_keys: 0 });+ mocks.redisKeyMetadataBatch.mockReset().mockResolvedValue([]);mocks.redisScanValues.mockReset().mockResolvedValue({ cursor: 0, keys: [], total_keys: 0 });}@@ -652,6 +655,17 @@ function keyInfo(rawKey: string): RedisKeyInfo {return { key_display: rawKey, key_raw: rawKey, key_type: "string", ttl: -1, size: 0, value_preview: "" };}+/**+ * A key the server listed without metadata.+ *+ * The payload leaves the type and the TTL out entirely instead of sending a+ * sentinel, so the frontend sees `undefined` for both. The fixtures have to+ * use that shape: a -2 sentinel is not what the server sends.+ */+function keyInfoWithoutMetadata(name: string): RedisKeyInfo {+ return { key_display: name, key_raw: btoa(name) };+}+async function searchByValue(host: HTMLElement, mode: "value" | "all" = "value") {const modeIndex = mode === "value" ? 1 : 2;host.querySelectorAll<HTMLButtonElement>(".redis-search-mode-button")[modeIndex]?.click();@@ -1251,3 +1265,274 @@ describe("RedisKeyBrowser group subtree fill on expand (issue #7162)", () => {expect(host.textContent).toContain("b");});});++// The footer is a permanent action bar. "Load more" only fills the rest of+// the keyspace (unchanged semantics). "Fetch all" has two levels: while+// something is left to fill it continues from the current scan cursor (the+// historical behaviour), and once the keyspace is exhausted it turns into+// "Reload all", which rescans from cursor 0 and can be repeated. The bar used+// to disappear as soon as the scan cursor reached the end, which left the+// user without any way to refresh the list.+describe("RedisKeyBrowser footer actions (permanent action bar)", () => {+ it("keeps the footer visible after the keyspace was scanned completely", async () => {+ mocks.infiniteScroll = false;+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [keyInfo("a")], total_keys: 1 });++ const host = mountBrowser();+ await settleThoroughly();++ const loadMore = host.querySelector<HTMLButtonElement>("[data-redis-load-more]");+ const fetchAll = host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]");+ expect(loadMore, "load more button").not.toBeNull();+ expect(fetchAll, "fetch all button").not.toBeNull();+ // Nothing left to fill: the button stays visible but disabled.+ expect(loadMore!.disabled).toBe(true);+ // Nothing is left to fill either, so the action becomes the full reload.+ expect(fetchAll!.disabled).toBe(false);+ expect(fetchAll!.textContent).toContain("redis.refetchAllKeys");+ });++ it("fills the rest of the keyspace first and only rescans from cursor 0 on the second click", async () => {+ mocks.infiniteScroll = false;+ mocks.redisScanKeysBatch.mockImplementation((_connectionId: string, _db: number, cursor: number) => {+ if (cursor === 0) return Promise.resolve({ cursor: 42, keys: [keyInfo("a")], total_keys: 10 });+ return Promise.resolve({ cursor: 0, keys: [keyInfo("b")], total_keys: 10 });+ });++ const host = mountBrowser();+ await settleThoroughly();++ const fetchAll = host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]")!;+ // Something is left to fill, so the button offers the continuation.+ expect(fetchAll.textContent).toContain("redis.fetchAllKeys");++ const callsBeforeFill = mocks.redisScanKeysBatch.mock.calls.length;+ fetchAll.click();+ await settleThoroughly();++ // The first click continues from the current cursor instead of starting over.+ expect(mocks.redisScanKeysBatch.mock.calls[callsBeforeFill]?.[2]).toBe(42);+ expect(host.textContent).toContain("b");+ // The finished sweep turns the same button into the reload action.+ expect(host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]")!.textContent).toContain("redis.refetchAllKeys");++ const callsBeforeReload = mocks.redisScanKeysBatch.mock.calls.length;+ host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]")!.click();+ await settleThoroughly();++ // The second click restarts at cursor 0 and replaces the current list.+ expect(mocks.redisScanKeysBatch.mock.calls[callsBeforeReload]?.[2]).toBe(0);+ });++ it("clears the list when a reload finds no keys at all", async () => {+ mocks.infiniteScroll = false;+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [{ ...keyInfo("a"), key_raw: btoa("a") }], total_keys: 1 });++ const host = mountBrowser();+ await settleThoroughly();++ const leaf = `[data-redis-leaf="${btoa("a")}"]`;+ expect(host.querySelector(leaf)).not.toBeNull();++ // Every key is gone, so the reload has to publish an empty snapshot+ // instead of keeping the rows of the previous one.+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [], total_keys: 0 });+ const fetchAll = host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]")!;+ expect(fetchAll.textContent).toContain("redis.refetchAllKeys");+ fetchAll.click();+ await settleThoroughly();++ expect(host.querySelector(leaf)).toBeNull();+ });++ it("drops a row from the no-expiry filter once the server resolves its expiry", async () => {+ mocks.infiniteScroll = false;+ const withoutMetadata = keyInfoWithoutMetadata("a");+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [withoutMetadata], total_keys: 1 });++ const host = mountBrowser();+ await settleThoroughly();+ // The automatic backfill is debounced, so it needs a real timer turn.+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ const leaf = `[data-redis-leaf="${btoa("a")}"]`;+ expect(host.querySelector(leaf)).not.toBeNull();++ // An unknown expiry is a member of the "no expiry" filter until the+ // server says the key really expires.+ host.querySelector<HTMLButtonElement>("[data-redis-no-expiry-filter]")!.click();+ await settleThoroughly();+ expect(host.querySelector(leaf)).not.toBeNull();++ // The server answers with a real expiry, so the row leaves the filter.+ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([{ key_raw: btoa("a"), key_type: "string", ttl: 3600 }]);+ host.querySelector<HTMLButtonElement>("[data-redis-backfill-metadata]")!.click();+ await settleThoroughly();++ expect(host.querySelector(leaf)).toBeNull();+ });++ it("keeps a row with an unresolved expiry in the no-expiry filter", async () => {+ mocks.infiniteScroll = false;+ // The server listed the key without metadata: the payload omits the type+ // and the TTL instead of sending a sentinel.+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [keyInfoWithoutMetadata("a")], total_keys: 1 });++ const host = mountBrowser();+ await settleThoroughly();+ // The automatic backfill is debounced, so it needs a real timer turn.+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ const leaf = `[data-redis-leaf="${btoa("a")}"]`;+ host.querySelector<HTMLButtonElement>("[data-redis-no-expiry-filter]")!.click();+ await settleThoroughly();+ // An unknown expiry is not "it expires": the row stays in the filter+ // until the server answers for it.+ expect(host.querySelector(leaf)).not.toBeNull();++ // The row is reachable for the backfill, so the backend is asked for it.+ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([{ key_raw: btoa("a"), key_type: "string", ttl: -1 }]);+ host.querySelector<HTMLButtonElement>("[data-redis-backfill-metadata]")!.click();+ await settleThoroughly();++ const metadataCalls = mocks.redisKeyMetadataBatch.mock.calls;+ expect(metadataCalls[metadataCalls.length - 1]?.[2]).toEqual([btoa("a")]);+ // The key never expires, so it stays in the filter and shows its badge.+ expect(host.querySelector(leaf)).not.toBeNull();+ expect(host.querySelector(`[data-redis-key-raw="${btoa("a")}"]`)!.textContent).toContain("string");+ });++ it("removes a key that the server reports as gone during the backfill", async () => {+ mocks.infiniteScroll = false;+ const withoutMetadata = keyInfoWithoutMetadata("a");+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [withoutMetadata], total_keys: 1 });++ const host = mountBrowser();+ await settleThoroughly();+ // The automatic backfill is debounced, so it needs a real timer turn.+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ const leaf = `[data-redis-leaf="${btoa("a")}"]`;+ expect(host.querySelector(leaf)).not.toBeNull();++ // The server answers that the key does not exist any more, so it leaves+ // the list instead of staying behind with an unknown expiry.+ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([{ key_raw: btoa("a"), key_type: "none", ttl: -2 }]);+ host.querySelector<HTMLButtonElement>("[data-redis-backfill-metadata]")!.click();+ await settleThoroughly();++ expect(host.querySelector(leaf)).toBeNull();+ });++ it("still refreshes the other rows when a batch also reports a gone key", async () => {+ mocks.infiniteScroll = false;+ const withoutMetadata = keyInfoWithoutMetadata;+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [withoutMetadata("a"), withoutMetadata("b")], total_keys: 2 });++ const host = mountBrowser();+ await settleThoroughly();+ // The automatic backfill is debounced, so it needs a real timer turn.+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ const goneLeaf = `[data-redis-leaf="${btoa("a")}"]`;+ const keptLeaf = `[data-redis-leaf="${btoa("b")}"]`;+ // The badge lives in the row, not in the checkbox of the leaf.+ const keptRow = `[data-redis-key-raw="${btoa("b")}"]`;+ expect(host.querySelector(goneLeaf)).not.toBeNull();+ expect(host.querySelector(keptLeaf)).not.toBeNull();+ // The type badge only shows up once the server answered for the key.+ expect(host.querySelector(keptRow)!.textContent).not.toContain("string");++ // One key is gone, the other one gets its real type and expiry.+ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([+ { key_raw: btoa("a"), key_type: "none", ttl: -2 },+ { key_raw: btoa("b"), key_type: "string", ttl: 3600 },+ ]);+ host.querySelector<HTMLButtonElement>("[data-redis-backfill-metadata]")!.click();+ await settleThoroughly();++ expect(host.querySelector(goneLeaf)).toBeNull();+ // The row that survived still has to show the metadata of this batch.+ expect(host.querySelector(keptRow)!.textContent).toContain("string");+ });++ it("removes the gone key from the Fetch All snapshot and refreshes the other rows", async () => {+ mocks.infiniteScroll = false;+ const withoutMetadata = keyInfoWithoutMetadata;+ mocks.redisScanKeysBatch.mockImplementation((_connectionId: string, _db: number, cursor: number) => {+ if (cursor === 0) return Promise.resolve({ cursor: 0, keys: [withoutMetadata("a"), withoutMetadata("b")], total_keys: 2 });+ return Promise.resolve({ cursor: 0, keys: [], total_keys: 0 });+ });++ const host = mountBrowser();+ await settleThoroughly();++ // The sweep publishes a stable row snapshot: the rendered rows do not+ // follow the flat list any more.+ host.querySelector<HTMLButtonElement>("[data-redis-fetch-all]")!.click();+ await settleThoroughly();+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ const keptRow = `[data-redis-key-raw="${btoa("b")}"]`;+ expect(host.querySelector(keptRow)).not.toBeNull();+ expect(host.querySelector(keptRow)!.textContent).not.toContain("string");+ const goneRow = `[data-redis-key-raw="${btoa("a")}"]`;+ expect(host.querySelector(goneRow)).not.toBeNull();++ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([+ { key_raw: btoa("a"), key_type: "none", ttl: -2 },+ { key_raw: btoa("b"), key_type: "string", ttl: 3600 },+ ]);+ host.querySelector<HTMLButtonElement>("[data-redis-backfill-metadata]")!.click();+ await settleThoroughly();++ // The row of the vanished key leaves the published snapshot as well.+ expect(host.querySelector(goneRow)).toBeNull();+ expect(host.querySelector(keptRow)!.textContent).toContain("string");+ });++ it("keeps the load-more action incremental instead of rescanning", async () => {+ mocks.infiniteScroll = false;+ mocks.redisScanKeysBatch.mockImplementation((_connectionId: string, _db: number, cursor: number) => {+ if (cursor === 0) return Promise.resolve({ cursor: 42, keys: [keyInfo("a")], total_keys: 10 });+ return Promise.resolve({ cursor: 0, keys: [keyInfo("b")], total_keys: 10 });+ });++ const host = mountBrowser();+ await settleThoroughly();++ const loadMore = host.querySelector<HTMLButtonElement>("[data-redis-load-more]")!;+ expect(loadMore.disabled).toBe(false);+ loadMore.click();+ await settleThoroughly();++ // The page continues from the previous cursor; it does not start over.+ const scanCalls = mocks.redisScanKeysBatch.mock.calls;+ expect(scanCalls[scanCalls.length - 1]?.[2]).toBe(42);+ expect(host.textContent).toContain("b");+ });++ it("fills the missing type and expiry metadata of the listed rows", async () => {+ mocks.infiniteScroll = false;+ const withoutMetadata = keyInfoWithoutMetadata("a");+ mocks.redisScanKeysBatch.mockResolvedValueOnce({ cursor: 0, keys: [withoutMetadata], total_keys: 1 });+ mocks.redisKeyMetadataBatch.mockResolvedValueOnce([{ key_raw: btoa("a"), key_type: "string", ttl: 3600 }]);++ const host = mountBrowser();+ await settleThoroughly();+ // The backfill is debounced, so it needs a real timer turn.+ await new Promise((resolve) => setTimeout(resolve, 250));+ await settleThoroughly();++ expect(mocks.redisKeyMetadataBatch).toHaveBeenCalled();+ const metadataCalls = mocks.redisKeyMetadataBatch.mock.calls;+ expect(metadataCalls[metadataCalls.length - 1]?.[2]).toEqual([btoa("a")]);+ // The type badge of the row is filled in by the backfill.+ expect(host.textContent).toContain("string");+ });+});diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.vue b/apps/desktop/src/components/redis/RedisKeyBrowser.vueindex d78672043b..a78b74cfdc 100644--- a/apps/desktop/src/components/redis/RedisKeyBrowser.vue+++ b/apps/desktop/src/components/redis/RedisKeyBrowser.vue@@ -28,7 +28,7 @@ import RedisGroupedKeyList from "./RedisGroupedKeyList.vue";import RedisKeyGroupingDialog from "./RedisKeyGroupingDialog.vue";import { defaultRedisKeyGrouping, type RedisKeyGrouping } from "@/lib/redis/redisKeyGrouping";import * as api from "@/lib/backend/api";-import type { RedisKeyInfo, RedisScanResult, RedisValue, HistoryEntry } from "@/lib/backend/api";+import type { RedisKeyInfo, RedisKeyMetadata, RedisScanResult, RedisValue, HistoryEntry } from "@/lib/backend/api";import { uuid } from "@/lib/common/utils";import { useConnectionStore } from "@/stores/connectionStore";import { useSettingsStore } from "@/stores/settingsStore";@@ -43,6 +43,7 @@ import {createRedisKeyTreeIndex,flattenVisibleRedisKeyTree,redisKeyNameCopyText,+ redisKeyPassesNoExpiryFilter,redisKeyToFlatTreeRow,updateRedisKeyInfoMetadataByRaw,updateRedisKeyTreeLeafMetadata,@@ -65,6 +66,7 @@ import { redisFuzzySearchScanBudget, createRedisKeyPatternMatcher, redisKeySearcimport { filterRedisKeyTemplates, resolveRedisKeyTemplates } from "@/lib/redis/redisKeyTemplates";import { forgetRedisKeySearchHistory, loadRedisKeySearchHistory, rememberRedisKeySearchHistory, type RedisKeySearchHistoryScope } from "@/lib/redis/redisKeySearchHistory";import { REDIS_SCAN_PAGE_SIZE_DEFAULT } from "@/lib/redis/redisKeyPattern";+import { REDIS_FETCH_ALL_SCAN_COUNT, redisFetchAllShouldInlineMetadata, trimRedisMetadataBackfillQueue } from "@/lib/redis/redisKeyMetadata";import { chunkRedisKeyRaws, collectUniqueRedisKeys } from "@/lib/redis/redisKeyBatch";import { getRedisCreateKeyTypeHelp, redisCreateKeyTypeHelpOptionOnOpen, shouldActivateRedisCreateKeyTypeHelpOnFocus } from "@/lib/redis/redisCreateKeyTypeHelp";import { optionHelpPanelOffsetTop } from "@/lib/common/optionHelpPanelOffset";@@ -154,6 +156,9 @@ const isFetchingAll = ref(false);const fetchAllSnapshotComplete = ref(false);const fetchAllStopRequested = ref(false);const fetchAllLoadedCount = ref(0);+/** Rows whose TYPE/TTL is still unknown and waits for a metadata backfill. */+const metadataBackfillRunning = ref(false);+const metadataBackfillProgress = ref<{ loaded: number; total: number } | null>(null);const rootRef = ref<HTMLElement>();const keyPaneRef = ref<HTMLElement>();const redisKeyScrollerRef = ref<InstanceType<typeof RecycleScroller> | null>(null);@@ -395,8 +400,9 @@ watch(redisKeySeparator, () => {rebuildTree();});const lastTotalKeys = ref(0);-// “仅看无过期”过滤开关:开启后只保留 TTL 为 -1(永不过期)的已加载 key。-// TTL 为 -2 的行(fetch-all 链路未查询 TTL)不会出现在过滤结果里。+// “仅看无过期”过滤开关:开启后只保留 TTL 为 -1(永不过期)的已加载 key,+// 以及 TTL 仍未知的行:未知的行先留在结果里,等补齐元数据拿到真实 TTL 后+// 再决定去留,否则整列未知 TTL 的行会在补齐前被全部藏起来。const noExpiryOnly = ref(restoredRedisKeyBrowserState?.noExpiryOnly ?? false);function persistRedisKeyBrowserState() {@@ -418,7 +424,7 @@ const filteredFlatKeys = computed(() => {const matchesPattern = localKeySearchActive.value ? localKeyPatternMatcher.value : undefined;if (!onlyNoExpiry && !matchesPattern) return flatKeys.value;void noExpiryProjectionEpoch.value;- return flatKeys.value.filter((key) => (!onlyNoExpiry || key.ttl === -1) && (!matchesPattern || matchesPattern(key.key_display, key.key_raw)));+ return flatKeys.value.filter((key) => (!onlyNoExpiry || redisKeyPassesNoExpiryFilter(key)) && (!matchesPattern || matchesPattern(key.key_display, key.key_raw)));});// 过滤后的树:独立重建而不复用 treeIndex,避免污染后续 SCAN 增量合并的全量树基准;// 分组 id 只由 db+路径决定,与全量树一致,因此展开状态可直接复用@@ -456,6 +462,15 @@ const fetchAllProgressText = computed(() => {}return t("redis.fetchAllProgressUnknown", { loaded: displayedKeyCount.value });});+// 底部「获取全部」有两级语义,按“还有没有剩余”决定:+// · 还有剩余(hasMore)→ 从当前游标续扫补齐,成本与旧版完全一致;+// · 已经扫完 → 从游标 0 重扫整个库并替换列表,可以反复触发。+// 过滤/搜索模式同样开放:重扫会带上当前的 pattern / 值查询条件重新扫一遍,+// key 模式由服务端 MATCH 过滤,值搜索则仍需逐键取值后在客户端过滤。+// 文案、提示与点击入口都从这一个判据派生,避免出现“文案说重扫、动作却是续扫”。+const fetchAllMode = computed<FetchAllMode>(() => (hasMore.value ? "resume" : "rescan"));+const fetchAllActionLabel = computed(() => (fetchAllMode.value === "resume" ? t("redis.fetchAllKeys") : t("redis.refetchAllKeys")));+const fetchAllActionHint = computed(() => (fetchAllMode.value === "resume" ? t("redis.fetchAllKeysHint") : t("redis.refetchAllKeysHint")));const keyCountText = computed(() => {if (loading.value && flatKeys.value.length === 0) return loadingEmptyText.value;if (!hasFilteredKeyRange.value && lastTotalKeys.value > 0) {@@ -681,6 +696,9 @@ function rollbackFetchAllPublication() {flatKeys.value = rollback.flatKeys;flatKeyByRaw = rollback.flatKeyByRaw;loadedKeyRaws = rollback.loadedKeyRaws;+ // The restored list is not the one the metadata counter was computed for,+ // so the counter has to follow the list again.+ recountMissingMetadata();treeKeys.value = rollback.treeKeys;treeIndex = rollback.treeIndex;expandedGroupIds.value = rollback.expandedGroupIds;@@ -741,10 +759,273 @@ function recordKeyTtlObservedAt(key: RedisKeyInfo) {}}+// ---------------------------------------------------------------------------+// Metadata backfill+//+// A full sweep inlines TYPE/TTL only for a bounded number of keys, so the+// metadata commands of one sweep never scale with the size of the keyspace.+// The keys beyond that budget are listed by name and their badges are filled+// in afterwards — for the rows the user can actually see, or for every loaded+// row on demand.+// ---------------------------------------------------------------------------++/** Keys resolved per backend round trip. */+const METADATA_BACKFILL_BATCH_SIZE = 500;+/** Rows inspected per backfill trigger. */+const METADATA_BACKFILL_WINDOW = 400;++/** Keys whose metadata was already resolved, so they are never asked twice. */+const metadataResolvedRaws = new Set<string>();+const metadataBackfillQueue = new Set<string>();+let metadataBackfillTimer: ReturnType<typeof setTimeout> | null = null;++/** Drops the TTL observation records of keys that are no longer listed. */+function pruneTtlObservationCache(keep: ReadonlySet<string>) {+ for (const keyRaw of Array.from(ttlObservedAtByRaw.keys())) {+ if (keep.has(keyRaw)) continue;+ ttlObservedAtByRaw.delete(keyRaw);+ positiveTtlKeyRaws.delete(keyRaw);+ }+}++function resetMetadataBackfillState() {+ metadataResolvedRaws.clear();+ metadataBackfillQueue.clear();+ metadataBackfillProgress.value = null;+ if (metadataBackfillTimer) {+ clearTimeout(metadataBackfillTimer);+ metadataBackfillTimer = null;+ }+}++/** True while the row still misses its type badge or its TTL. */+function redisKeyNeedsMetadata(key: RedisKeyInfo): boolean {+ if (!key.key_type) return true;+ return key.ttl === undefined || key.ttl === -2;+}++/** Number of loaded keys whose type badge or TTL is still unknown. */+const missingMetadataCount = ref(0);++function countMissingMetadata(keys: readonly RedisKeyInfo[]): number {+ let missing = 0;+ for (const key of keys) {+ // A key the server already answered for is resolved, not missing: its+ // answer may well be "the key does not exist any more".+ if (redisKeyNeedsMetadata(key) && !metadataResolvedRaws.has(key.key_raw)) missing++;+ }+ return missing;+}++function recountMissingMetadata() {+ missingMetadataCount.value = countMissingMetadata(flatKeys.value);+}++/**+ * The rows the user can currently see, so the backfill stays cheap.+ *+ * The scroller is queried defensively: it may not be mounted yet, and a+ * partially initialised scroller does not expose the viewport helpers. In+ * that case the backfill falls back to the head of the list, which is still+ * a valid (if slightly less targeted) window.+ */+function metadataBackfillWindow(): RedisKeyTreeRow[] {+ const rows = visibleRows.value;+ if (rows.length === 0) return rows;+ const scroller = redisKeyScroller();+ if (typeof scroller?.getScroll !== "function" || typeof scroller.findItemIndex !== "function") {+ return rows.slice(0, METADATA_BACKFILL_WINDOW);+ }+ const { start, end } = scroller.getScroll();+ const first = Math.max(0, scroller.findItemIndex(start));+ const lastIndex = scroller.findItemIndex(end ?? start);+ const last = Math.min(rows.length - 1, Math.max(first, lastIndex));+ return rows.slice(first, last + 1);+}++/**+ * Collects the loaded keys whose metadata is still missing.+ *+ * The visible window is the cheapest source, but it is empty while a custom+ * grouping renders the list: the grouped rows are not the loaded keys, so the+ * head of the loaded list is used instead. Without that fallback the badges of+ * a grouped list would never be filled.+ */+function metadataBackfillCandidates(limit: number): string[] {+ const candidates: string[] = [];+ const seen = new Set<string>();+ const rows = metadataBackfillWindow();+ const infos: (RedisKeyInfo | undefined)[] = [];+ if (rows.length > 0) {+ for (const row of rows) {+ if (row.node.kind !== "leaf") continue;+ infos.push(flatKeyByRaw.get(row.node.keyRaw));+ }+ } else {+ infos.push(...flatKeys.value.slice(0, METADATA_BACKFILL_WINDOW));+ }+ for (const info of infos) {+ if (!info) continue;+ const keyRaw = info.key_raw;+ if (seen.has(keyRaw)) continue;+ seen.add(keyRaw);+ if (metadataResolvedRaws.has(keyRaw)) continue;+ if (!redisKeyNeedsMetadata(info)) continue;+ candidates.push(keyRaw);+ if (candidates.length >= limit) break;+ }+ return candidates;+}++/**+ * Queues the visible rows that still miss metadata and flushes them shortly.+ *+ * The backfill is a best-effort enhancement, so it must never break the load+ * that scheduled it: any failure here is swallowed instead of rejecting the+ * caller's promise.+ *+ * The visible window can queue faster than the backend answers, so the queue+ * is capped. The oldest entries are dropped first: they belong to rows the+ * user scrolled past, and their badges are filled in again when they are+ * listed anew.+ */+function scheduleMetadataBackfill() {+ if (!redisBrowserIsActive) return;+ try {+ for (const keyRaw of metadataBackfillCandidates(METADATA_BACKFILL_WINDOW)) {+ metadataBackfillQueue.add(keyRaw);+ }+ trimRedisMetadataBackfillQueue(metadataBackfillQueue);+ } catch {+ metadataBackfillQueue.clear();+ return;+ }+ if (metadataBackfillQueue.size === 0) return;+ if (metadataBackfillTimer) return;+ metadataBackfillTimer = setTimeout(() => {+ metadataBackfillTimer = null;+ void flushMetadataBackfill();+ }, 120);+}++/** Writes resolved metadata back into the flat list and the tree. */+function applyMetadataBatch(metadata: readonly RedisKeyMetadata[]): void {+ let changed = false;+ let noExpiryMembershipChanged = false;+ const vanishedKeyRaws = new Set<string>();+ for (const entry of metadata) {+ const existing = flatKeyByRaw.get(entry.key_raw);+ if (!existing) continue;+ // The server answered "none": the key does not exist any more. It leaves+ // the list instead of staying behind as a row whose expiry is unknown.+ if (entry.key_type === "none") {+ vanishedKeyRaws.add(entry.key_raw);+ metadataResolvedRaws.add(entry.key_raw);+ continue;+ }+ // A key the server answered for is resolved, even when the answer is+ // "the key does not exist any more": it will never be asked again, so it+ // must stop counting as a key whose metadata is missing.+ const wasMissing = redisKeyNeedsMetadata(existing) && !metadataResolvedRaws.has(entry.key_raw);+ metadataResolvedRaws.add(entry.key_raw);+ if (wasMissing) missingMetadataCount.value = Math.max(0, missingMetadataCount.value - 1);+ const previousTtl = existing.ttl ?? -2;+ const nextType = entry.key_type || existing.key_type;+ const nextTtl = entry.ttl;+ if (previousTtl === nextTtl && existing.key_type === nextType) continue;+ // The filter membership follows the projection predicate, not the raw+ // TTL: an unknown TTL (-2) is a member until it is resolved, so only the+ // predicate knows whether the row belongs into the projection.+ if (redisKeyPassesNoExpiryFilter({ ttl: previousTtl }) !== redisKeyPassesNoExpiryFilter({ ttl: nextTtl })) {+ noExpiryMembershipChanged = true;+ }+ // The metadata write mutates the listed record in place, so the previous+ // state has to be captured before it happens.+ const next: RedisKeyInfo = { ...existing, key_type: nextType, ttl: nextTtl };+ updateRedisKeyInfoMetadataByRaw(flatKeyByRaw, next);+ if (treeIndex) updateRedisKeyTreeLeafMetadata(treeIndex, next);+ recordKeyTtlObservedAt(next);+ changed = true;+ }+ if (vanishedKeyRaws.size > 0) {+ // The rows are gone, so the list and the tree are rebuilt for them.+ removeKnownKeys(vanishedKeyRaws);+ }+ // The epochs are bumped even when a key vanished: the metadata of the other+ // keys was written in place, and the epoch is what makes the rows re-render+ // with the new type badge and TTL. It must not depend on the removal path.+ if (!changed) return;+ if (noExpiryMembershipChanged) noExpiryProjectionEpoch.value++;+ keyMetadataEpoch.value++;+ syncListTtlTimer();+}++/**+ * Resolves the metadata of the given keys, one batch at a time.+ *+ * The automatic backfill and the "fill all" button ask the backend for the+ * same thing, so they share this loop: only the candidate set, the progress+ * reporting and the way a failure is reported differ.+ */+async function runMetadataBackfill(candidates: readonly string[], options: { reportProgress?: boolean; onFailure?: (error: unknown) => void } = {}): Promise<void> {+ if (metadataBackfillRunning.value) return;+ if (candidates.length === 0) return;+ metadataBackfillRunning.value = true;+ const requestId = searchRequestId;+ if (options.reportProgress) metadataBackfillProgress.value = { loaded: 0, total: candidates.length };+ try {+ for (let offset = 0; offset < candidates.length; offset += METADATA_BACKFILL_BATCH_SIZE) {+ if (!redisBrowserIsActive) return;+ // A later load replaced the list: the remaining batches belong to rows+ // that no longer exist and must not be asked for.+ if (requestId !== searchRequestId) return;+ const batch = candidates.slice(offset, offset + METADATA_BACKFILL_BATCH_SIZE);+ const metadata = await api.redisKeyMetadataBatch(props.connectionId, props.db, batch);+ if (requestId !== searchRequestId) return;+ applyMetadataBatch(metadata);+ if (options.reportProgress) metadataBackfillProgress.value = { loaded: offset + batch.length, total: candidates.length };+ }+ } catch (error) {+ if (options.onFailure) options.onFailure(error);+ else console.warn("[DBX] Redis key metadata backfill failed", error);+ } finally {+ metadataBackfillRunning.value = false;+ if (options.reportProgress) metadataBackfillProgress.value = null;+ }+}++/**+ * Flushes the queued keys.+ *+ * A failed batch is not queued again: the automatic backfill would retry it+ * forever without any progress. The next trigger asks for the visible rows+ * again, which puts the same keys back into the queue.+ */+async function flushMetadataBackfill() {+ if (metadataBackfillRunning.value) return;+ const batch = [...metadataBackfillQueue].slice(0, METADATA_BACKFILL_BATCH_SIZE);+ if (batch.length === 0) return;+ for (const keyRaw of batch) metadataBackfillQueue.delete(keyRaw);+ await runMetadataBackfill(batch);+ if (metadataBackfillQueue.size > 0) scheduleMetadataBackfill();+}++/** Resolves the metadata of every loaded row, not only the visible ones. */+async function backfillAllKeyMetadata() {+ if (metadataBackfillRunning.value) return;+ const pending = flatKeys.value.filter((key) => redisKeyNeedsMetadata(key) && !metadataResolvedRaws.has(key.key_raw)).map((key) => key.key_raw);+ if (pending.length === 0) return;+ await runMetadataBackfill(pending, { reportProgress: true, onFailure: (error) => toast(errorMessage(error), 5000) });+}++/** True when at least one loaded row still misses its type badge or TTL. */+const hasMissingKeyMetadata = computed(() => missingMetadataCount.value > 0);+function appendFlatKeyRecords(keys: readonly RedisKeyInfo[]) {if (keys.length === 0) return;for (const key of keys) flatKeyByRaw.set(key.key_raw, key);flatKeys.value = [...flatKeys.value, ...keys];+ missingMetadataCount.value += countMissingMetadata(keys);}function replaceFlatKeyRecords(keys: RedisKeyInfo[]) {@@ -752,6 +1033,7 @@ function replaceFlatKeyRecords(keys: RedisKeyInfo[]) {flatKeyByRaw.clear();for (const key of keys) flatKeyByRaw.set(key.key_raw, key);flatKeys.value = keys;+ missingMetadataCount.value = countMissingMetadata(keys);}// 列表行展示的 TTL:正 TTL 按观测时刻到当前时刻的流逝本地递减;-1/-2 原样透传@@ -1125,16 +1407,34 @@ async function fetchScanPage(requestId = searchRequestId, operationId?: number,return { cursor, keys: [], total_keys: totalKeys };}+/**+ * One page of a batch scan.+ *+ * `result` is what the list shows: the server's answer narrowed to the+ * connection scope. `metadataKeyCount` is what the server was asked about:+ * the inline TYPE/TTL metadata is paid for every key it answered, including+ * the ones the scope filter drops afterwards. Counting the filtered rows+ * instead would let the metadata cost grow with the keyspace while the+ * budget still reads as "not reached yet".+ */+interface ScanBatchPage {+ result: RedisScanResult;+ metadataKeyCount: number;+}+/// Batch-scan variant that performs multiple SCAN iterations server-side./// Dramatically reduces frontend↔backend roundtrips for bulk loading.-async function fetchScanBatchPage(maxIterations: number, options: { count?: number; includeTypes?: boolean } = {}): Promise<RedisScanResult> {+async function fetchScanBatchPage(maxIterations: number, options: { count?: number; includeTypes?: boolean } = {}): Promise<ScanBatchPage> {// Value search cannot be batched because each key requires a GET.// Keep its configured COUNT independent of the key-only bulk override.if (isValueSearchMode.value && valueQuery.value) {- return filterScanResultToScope(await api.redisScanValues(props.connectionId, props.db, scanCursor.value, defaultScopePattern.value, valueQuery.value, redisScanPageSize.value, searchMode.value === "all"));+ const scanned = await api.redisScanValues(props.connectionId, props.db, scanCursor.value, defaultScopePattern.value, valueQuery.value, redisScanPageSize.value, searchMode.value === "all");+ // The value scan never asks for inline metadata.+ return { result: filterScanResultToScope(scanned), metadataKeyCount: 0 };}const pageSize = options.count ?? redisScanPageSize.value;- return filterScanResultToScope(await api.redisScanKeysBatch(props.connectionId, props.db, scanCursor.value, scanKeyPattern.value, pageSize, maxIterations, options.includeTypes ?? false));+ const scanned = await api.redisScanKeysBatch(props.connectionId, props.db, scanCursor.value, scanKeyPattern.value, pageSize, maxIterations, options.includeTypes ?? false);+ return { result: filterScanResultToScope(scanned), metadataKeyCount: scanned.keys.length };}function appendScanResult(result: RedisScanResult, options: { updateTree?: boolean; buffer?: RedisKeyInfo[] } = {}): number {@@ -1180,7 +1480,7 @@ function appendScanResult(result: RedisScanResult, options: { updateTree?: boolereturn newKeys.length;}-function bufferFetchAllScanResult(result: RedisScanResult, buffer: RedisKeyInfo[], bufferedKeyRaws: Set<string>): number {+function bufferFetchAllScanResult(result: RedisScanResult, buffer: RedisKeyInfo[], bufferedKeyRaws: Set<string>, baseLoadedCount = flatKeys.value.length): number {let added = 0;for (const key of result.keys) {if (loadedKeyRaws.has(key.key_raw) || bufferedKeyRaws.has(key.key_raw)) continue;@@ -1193,7 +1493,7 @@ function bufferFetchAllScanResult(result: RedisScanResult, buffer: RedisKeyInfo[hasMore.value = result.cursor !== 0;if (result.total_keys > 0 || (result.cursor === 0 && result.keys.length === 0 && !hasFilteredKeyRange.value)) lastTotalKeys.value = result.total_keys;connectionStore.updateRedisDbKeyStats(props.connectionId, props.db, {- loaded: hasFilteredKeyRange.value ? undefined : flatKeys.value.length + buffer.length,+ loaded: hasFilteredKeyRange.value ? undefined : baseLoadedCount + buffer.length,total: result.total_keys > 0 || (result.cursor === 0 && result.keys.length === 0 && !hasFilteredKeyRange.value) ? result.total_keys : undefined,});return added;@@ -1224,6 +1524,7 @@ async function loadKeys() {loadedKeyRaws.clear();ttlObservedAtByRaw.clear();positiveTtlKeyRaws.clear();+ resetMetadataBackfillState();subtreeFilledGroupIds.clear();subtreePendingGroupCursors.clear();subtreeFillOperations.clear();@@ -1260,6 +1561,9 @@ async function loadKeys() {if (succeeded && requestId === searchRequestId) {void maybeAutoLoadMoreRedisKeys();}+ // Rows that were listed without inline metadata still need their type and+ // expiry information before the badges can be filled in.+ scheduleMetadataBackfill();}async function loadMore(iterationBudget?: ScanIterationBudget) {@@ -1293,6 +1597,7 @@ async function loadMore(iterationBudget?: ScanIterationBudget) {resumePendingGroupSubtrees(requestId);}void maybeAutoLoadMoreRedisKeys();+ scheduleMetadataBackfill();}}@@ -1345,6 +1650,11 @@ function onRedisKeyScroll(event: Event) {if (redisInfiniteScrollFrame) return;redisInfiniteScrollFrame = requestAnimationFrame(() => {redisInfiniteScrollFrame = 0;+ // Rows that scrolled into view may still miss their type badge and TTL+ // because the sweep skipped metadata for the keys beyond its budget.+ // The scan of the visible window runs inside the frame callback: a raw+ // scroll event fires far more often than the display refreshes.+ scheduleMetadataBackfill();const shouldLoad = shouldLoadMoreRedisKeys({enabled: redisInfiniteScrollEnabled.value,hasMore: hasMore.value,@@ -1361,9 +1671,9 @@ function onRedisKeyScroll(event: Event) {});}-// Fetch-all uses large key-only SCAN pages and rebuilds the tree once at the-// end; per-page tree sorting dominates runtime on million-key pattern scans.-const FETCH_ALL_SCAN_COUNT = 50000;+// Fetch-all rebuilds the tree once at the end; per-page tree sorting+// dominates runtime on million-key pattern scans. The page size lives next to+// the metadata budget, because the budget is derived from it.const FETCH_ALL_BATCH_ITERATIONS = 8;const FETCH_ALL_PUBLISH_CHUNK_SIZE = 25_000;@@ -1477,8 +1787,22 @@ async function publishFetchAllVisibleRows(rows: readonly RedisKeyTreeRow[], requreturn fetchAllPublicationIsCurrent(requestId);}-async function fetchAll(): Promise<boolean> {- if (!hasMore.value || isFetchingAll.value) return false;+/**+ * How a full sweep treats the keys that are already listed.+ *+ * - "resume" keeps the current rows and only fills the rest of the keyspace.+ * - "rescan" starts over at cursor 0 and *replaces* the list, so the result is+ * a fresh snapshot of the whole database (this is what the footer's "Fetch+ * all" / "Refetch all" button does).+ */+type FetchAllMode = "resume" | "rescan";++async function fetchAll(mode: FetchAllMode = "resume"): Promise<boolean> {+ if (isFetchingAll.value) return false;+ const rescan = mode === "rescan";+ // A resume can only continue an unfinished sweep; a rescan may start at any+ // time, including when the previous sweep already reached the end.+ if (!rescan && !hasMore.value) return false;const requestId = searchRequestId;const fetchAllCoversScope = searchMode.value === "key" && !isSearchMode.value;const bufferedKeys: RedisKeyInfo[] = [];@@ -1515,32 +1839,66 @@ async function fetchAll(): Promise<boolean> {activateFetchAllVisibleRows();isFetchingAll.value = true;fetchAllStopRequested.value = false;- fetchAllLoadedCount.value = flatKeys.value.length;+ // A rescan rebuilds the list from scratch: it starts at cursor 0 and the+ // previously loaded keys are only kept as the rollback backup. The dedupe set+ // is replaced for the same reason — keeping the old one would drop every+ // rescanned key as "already loaded".+ if (rescan) {+ scanCursor.value = 0;+ hasMore.value = true;+ loadedKeyRaws = new Set<string>();+ // The previous sweep's snapshot no longer describes the list once the+ // rescan starts replacing it.+ fetchAllSnapshotComplete.value = false;+ }+ fetchAllLoadedCount.value = rescan ? 0 : flatKeys.value.length;let changed = false;let completed = false;let publicationSucceeded = true;+ // The sweep pays for inline TYPE/TTL metadata only for a bounded number of+ // keys. The first batch is inlined unconditionally — the scan asks Redis for+ // COUNT keys per round trip, so that batch costs at most 2 * COUNT+ // commands. Every later batch is inlined only while the running total stays+ // inside the budget, which keeps one sweep at that order of magnitude no+ // matter how large the keyspace is. The keys beyond the budget are filled in+ // afterwards, for the rows the user actually looks at.+ let inlineMetadataKeys = 0;+ let includeTypes = true;try {while (requestId === searchRequestId && !fetchAllStopRequested.value && hasMore.value) {- const result = await fetchScanBatchPage(FETCH_ALL_BATCH_ITERATIONS, {- count: FETCH_ALL_SCAN_COUNT,- includeTypes: false,+ const page = await fetchScanBatchPage(FETCH_ALL_BATCH_ITERATIONS, {+ count: REDIS_FETCH_ALL_SCAN_COUNT,+ includeTypes,});if (requestId !== searchRequestId) break;- changed = bufferFetchAllScanResult(result, bufferedKeys, bufferedKeyRaws) > 0 || changed;- fetchAllLoadedCount.value = flatKeys.value.length + bufferedKeys.length;+ changed = bufferFetchAllScanResult(page.result, bufferedKeys, bufferedKeyRaws, rescan ? 0 : flatKeys.value.length) > 0 || changed;+ fetchAllLoadedCount.value = (rescan ? 0 : flatKeys.value.length) + bufferedKeys.length;+ if (includeTypes) {+ // The budget counts the keys the sweep already asked the server+ // about, so it holds for every mode: a continuation, a rescan and a+ // filtered sweep all count the keys they actually matched. The scope+ // filter is applied after the answer arrived, so the keys it drops+ // were paid for as well and have to be part of the count.+ inlineMetadataKeys += page.metadataKeyCount;+ if (!redisFetchAllShouldInlineMetadata(inlineMetadataKeys)) includeTypes = false;+ }}completed = requestId === searchRequestId && !fetchAllStopRequested.value && !hasMore.value;} finally {if (requestId === searchRequestId) {let published = !changed && !fetchAllStopRequested.value;try {- if (changed) {- snapshotConfig.flatRows = customGrouping.value.enabled || useFlatSearchResults(initialFlatKeys.length + bufferedKeys.length);+ // A rescan has to publish even when it found nothing: the point of+ // the action is to replace the list with the current state of the+ // database, and an empty database means an empty list.+ if (rescan || changed) {+ const seedBatches = rescan ? [bufferedKeys] : [initialFlatKeys, bufferedKeys];+ snapshotConfig.flatRows = customGrouping.value.enabled || useFlatSearchResults(seedBatches.reduce((total, batch) => total + batch.length, 0));snapshotConfig.expandAll = false;snapshotConfig.expandedGroupIds = expandedGroupIds.value;snapshotConfig.noExpiryOnly = noExpiryOnly.value;activateFetchAllVisibleRows();- const snapshot = await buildRedisKeySnapshotCooperatively([initialFlatKeys, bufferedKeys], snapshotConfig, {+ const snapshot = await buildRedisKeySnapshotCooperatively(seedBatches, snapshotConfig, {shouldContinue: () => requestId === searchRequestId && redisBrowserIsActive && !fetchAllStopRequested.value,});if (snapshot && requestId === searchRequestId && redisBrowserIsActive) {@@ -1552,6 +1910,11 @@ async function fetchAll(): Promise<boolean> {expandedGroupIds.value = snapshot.expandedGroupIds;fetchAllFilteredKeyCount.value = snapshotConfig.noExpiryOnly ? snapshot.filteredKeyCount : null;refreshSelectedGroupLeafCounts();+ pruneTtlObservationCache(snapshot.loadedKeyRaws);+ // The resolved set belongs to the previous list, so it is dropped+ // before the counter is recomputed for the new one.+ resetMetadataBackfillState();+ recountMissingMetadata();published = await publishFetchAllVisibleRows(snapshot.visibleRows, requestId);}}@@ -1587,6 +1950,7 @@ async function fetchAll(): Promise<boolean> {publicationSucceeded = false;}}+ if (publicationSucceeded) scheduleMetadataBackfill();return completed && publicationSucceeded;}@@ -1594,6 +1958,26 @@ function stopFetchAll() {fetchAllStopRequested.value = true;}+/**+ * Footer entry point for the full sweep.+ *+ * The button has two levels, decided by whether anything is left to fill:+ *+ * - "resume" (the default) continues from the current scan cursor and fills+ * the rest of the keyspace. This is the historical behaviour and costs+ * exactly what it always did.+ * - "rescan" restarts at cursor 0 and replaces the current list with a fresh+ * snapshot of the whole keyspace. It is what the button becomes once the+ * keyspace is exhausted, and it can be triggered again and again.+ *+ * Both levels are available in every mode. A rescan inside a search re-runs+ * that search: a key-mode search is filtered by the server-side MATCH, while+ * a value search still has to fetch and match every value on the client.+ */+function startFetchAll() {+ void fetchAll(fetchAllMode.value).catch((error) => toast(errorMessage(error), 5000));+}+// 展开分组时的定向补扫:树模式的自动加载只覆盖有界 SCAN 预算内的键,// 未扫到的分组在树里完全不存在(搜索能找到、树里看不到)。展开分组时用// `前缀:*` 模式以独立游标扫描该子树,让"展开即可见"成立;补扫结果经@@ -1813,15 +2197,28 @@ function onRowClick(node: RedisKeyTreeNode, event?: MouseEvent) {activeSidePanel.value = "detail";}-function removeKnownKey(keyRaw: string) {- if (!flatKeyByRaw.has(keyRaw)) return;+/**+ * Removes keys that no longer exist.+ *+ * A batch of vanished keys is removed in one pass: rebuilding the list and+ * the tree once per key would cost O(keys * list) on a large keyspace.+ */+function removeKnownKeys(keyRaws: ReadonlySet<string>) {+ const present = new Set<string>();+ for (const keyRaw of keyRaws) {+ if (flatKeyByRaw.has(keyRaw)) present.add(keyRaw);+ }+ if (present.size === 0) return;const reloadSearch = localKeySearchActive.value;invalidateFetchAllForStructuralMutation();- loadedKeyRaws.delete(keyRaw);- ttlObservedAtByRaw.delete(keyRaw);- positiveTtlKeyRaws.delete(keyRaw);- replaceFlatKeyRecords(flatKeys.value.filter((key) => key.key_raw !== keyRaw));- if (selectedKeyRaw.value === keyRaw) selectedKeyRaw.value = null;+ for (const keyRaw of present) {+ loadedKeyRaws.delete(keyRaw);+ ttlObservedAtByRaw.delete(keyRaw);+ positiveTtlKeyRaws.delete(keyRaw);+ metadataResolvedRaws.add(keyRaw);+ if (selectedKeyRaw.value === keyRaw) selectedKeyRaw.value = null;+ }+ replaceFlatKeyRecords(flatKeys.value.filter((key) => !present.has(key.key_raw)));if (useFlatKeySearchRows.value) {treeKeys.value = [];treeIndex = null;@@ -1831,7 +2228,7 @@ function removeKnownKey(keyRaw: string) {}connectionStore.updateRedisDbKeyStats(props.connectionId, props.db, {loaded: hasFilteredKeyRange.value ? undefined : flatKeys.value.length,- totalDelta: -1,+ totalDelta: -present.size,});// The remaining records still cover the old complete scope. Once that cache// is invalidated, reload the active query instead of displaying every record.@@ -1841,6 +2238,10 @@ function removeKnownKey(keyRaw: string) {}}+function removeKnownKey(keyRaw: string) {+ removeKnownKeys(new Set([keyRaw]));+}+function onKeyDeleted(keyRaw: string) {removeKnownKey(keyRaw);}@@ -1903,7 +2304,7 @@ function onKeyLoaded(value: RedisValue) {}const keyInfo = redisValueToKeyInfo(value);const previousTtl = flatKeyByRaw.get(keyInfo.key_raw)?.ttl ?? -2;- const noExpiryMembershipChanged = (previousTtl === -1) !== (keyInfo.ttl === -1);+ const noExpiryMembershipChanged = redisKeyPassesNoExpiryFilter({ ttl: previousTtl }) !== redisKeyPassesNoExpiryFilter(keyInfo);if (!updateRedisKeyInfoMetadataByRaw(flatKeyByRaw, keyInfo)) return;if (groupRefresh.value) invalidateScanRequests(false);// 详情面板回写了最新的 TTL,同步刷新观测时刻,保证两侧倒计时一致@@ -2170,7 +2571,7 @@ function applyKeyTtlMetadata(keyRaw: string, ttl: number): boolean {if (groupRefresh.value) invalidateScanRequests(false);recordKeyTtlObservedAt(nextKeyInfo);if (treeIndex) updateRedisKeyTreeLeafMetadata(treeIndex, nextKeyInfo);- return (previousTtl === -1) !== (ttl === -1);+ return redisKeyPassesNoExpiryFilter({ ttl: previousTtl }) !== redisKeyPassesNoExpiryFilter({ ttl });}function applyBatchExpiryMetadata(keyRaws: readonly string[], policy: RedisExpiryPolicy) {@@ -3835,20 +4236,36 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });<div v-if="searchTreeLimitReached && !showCustomGrouping" class="shrink-0 border-t px-3 py-2 text-center text-xs text-muted-foreground">{{ t("redis.fuzzyTreeLimit", { count: flatKeys.length }) }}</div>- <div v-if="hasMore && !isFetchingAll" class="shrink-0 border-t px-2 py-1.5 flex items-center gap-1.5">- <Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loadingMore || loading || searchPending || mutatingKeys" @click="loadMore()">+ <!--+ 底部操作区常驻,不再随 hasMore 卸载:+ · 加载更多只做增量补齐(原语义不变),扫尽后置灰并显示“已全部加载”;+ · 获取全部有两级:还有剩余时从当前游标续扫补齐(与旧版一致),+ 扫完之后变成“重新加载全部”,点击则从游标 0 重扫整个库并替换列表,+ 可以反复触发。+ -->+ <div v-if="!isFetchingAll && (flatKeys.length > 0 || hasMore)" class="shrink-0 border-t px-2 py-1.5 flex items-center gap-1.5">+ <Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loadingMore || loading || searchPending || mutatingKeys || !hasMore" :title="hasMore ? t('redis.loadMoreKeysHint') : t('redis.loadMoreAllLoadedHint')" data-redis-load-more @click="loadMore()"><Loader2 v-if="loadingMore" class="w-3 h-3 mr-1.5 animate-spin" />- {{ t("redis.loadMoreKeys") }}+ {{ hasMore ? t("redis.loadMoreKeys") : t("redis.allKeysLoaded") }}+ </Button>+ <Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loading || searchPending || mutatingKeys" :title="fetchAllActionHint" data-redis-fetch-all @click="startFetchAll">+ {{ fetchAllActionLabel }}</Button>- <Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loading || searchPending || mutatingKeys || !hasMore" @click="fetchAll">- {{ t("redis.fetchAllKeys") }}+ </div>+ <div v-if="!isFetchingAll && hasMissingKeyMetadata" class="shrink-0 border-t px-2 py-1.5 flex items-center gap-1.5">+ <span class="text-[11px] text-muted-foreground flex-1 truncate" :title="t('redis.backfillMetadataHint')">+ {{ metadataBackfillRunning && metadataBackfillProgress ? t("redis.backfillMetadataProgress", { loaded: metadataBackfillProgress.loaded, total: metadataBackfillProgress.total }) : t("redis.backfillMetadataPending") }}+ </span>+ <Button variant="ghost" size="sm" class="h-7 text-xs shrink-0" :disabled="metadataBackfillRunning || mutatingKeys" data-redis-backfill-metadata @click="backfillAllKeyMetadata">+ <Loader2 v-if="metadataBackfillRunning" class="w-3 h-3 mr-1.5 animate-spin" />+ {{ t("redis.backfillMetadata") }}</Button></div><div v-if="isFetchingAll" class="shrink-0 border-t px-2 py-1.5 space-y-1"><div class="text-xs text-muted-foreground text-center">{{ fetchAllProgressText }}</div>- <Button variant="destructive" size="sm" class="h-7 text-xs w-full" :disabled="fetchAllStopRequested || mutatingKeys" @click="stopFetchAll">+ <Button variant="destructive" size="sm" class="h-7 text-xs w-full" :disabled="fetchAllStopRequested || mutatingKeys" :title="t('redis.stopFetchAllHint')" @click="stopFetchAll">{{ t("redis.stopFetchAll") }}</Button></div>diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 8307e31284..44c71f5f76 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -5679,8 +5679,19 @@ export default withEnglishFallback({searchingValues: "Dəyərlər axtarılır...",searchingAll: "Açarlar və dəyərlər axtarılır...",loadMoreKeys: "Daha çox açar yüklə",+ loadMoreKeysHint: "Daha çox açar yükləyin. Yüklənmiş açarlar yerində qalır.",fetchAllKeys: "Hamısını gətir",+ fetchAllKeysHint: "Qalan açarları bir dəfədə yükləyin (cari mövqeydən davam edir), sonra siyahını nəticə ilə əvəz edin.",+ refetchAllKeys: "Hamısını yenidən yüklə",+ allKeysLoaded: "Bütün açarlar yükləndi",+ loadMoreAllLoadedHint: "Bütün baza skan edildi, yüklənəcək əlavə açar yoxdur. Hamısını yenidən yükləmək üçün «Hamısını yenidən yüklə» düyməsindən istifadə edin.",+ refetchAllKeysHint: "Bütun bazanı yenidən skan edin və cari siyahını nəticə ilə əvəz edin.",+ backfillMetadata: "Tipi və müddəti tamamla",+ backfillMetadataPending: "Bəzi açarların tipi və müddəti hələ məlum deyil",+ backfillMetadataProgress: "Metadatamallar tamamlanır {loaded} / {total}",+ backfillMetadataHint: "Bu baza açar adları ilə yükləndi, tip və müddət məlum deyil. Bütün yüklənmiş açarlar üçün tamamlamaq olar.",stopFetchAll: "Dayandır",+ stopFetchAllHint: "Dayandırmaq bu skanı tərk edir: yığılan açarlar saxlanmır və siyahı skan əvvəlki vəziyyətinə qayıdır.",fetchAllProgress: "{total} açardan {loaded} yüklənib",fetchAllProgressUnknown: "{loaded} açar yüklənib",items: "{count} element",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex 4ad98bada1..63dc1ff03f 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -7877,8 +7877,19 @@ export default {searchingValues: "Searching values...",searchingAll: "Searching keys and values...",loadMoreKeys: "Load more keys",- fetchAllKeys: "Fetch all",- stopFetchAll: "Stop",+ loadMoreKeysHint: "Scan one more batch of keys and append it to the list. The keys that are already loaded stay.",+ fetchAllKeys: "Load all",+ fetchAllKeysHint: "Finish the remaining keys in one go (continues from the current position), then replace the list with the result.",+ refetchAllKeys: "Reload all",+ allKeysLoaded: "All keys loaded",+ loadMoreAllLoadedHint: 'The whole database was scanned, there is nothing more to load. Use "Reload all" to scan it again from the start.',+ refetchAllKeysHint: "Rescan the whole database from the start and replace the current list with the result.",+ backfillMetadata: "Fill type & expiry",+ backfillMetadataPending: "Some keys still miss their type and expiry time",+ backfillMetadataProgress: "Filling metadata {loaded} / {total}",+ backfillMetadataHint: "This database was listed without type and expiry information. Fill it for every loaded key.",+ stopFetchAll: "Stop scan",+ stopFetchAllHint: "Stopping abandons this scan. The keys it collected are not kept and the list goes back to what it was before the scan.",fetchAllProgress: "{loaded} of {total} keys loaded",fetchAllProgressUnknown: "{loaded} keys loaded",items: "{count} items",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex ecc4a26bfa..a2035b6558 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -6914,8 +6914,19 @@ export default withEnglishFallback({searchingValues: "Buscando por valor...",searchingAll: "Buscando claves y valores...",loadMoreKeys: "Cargar más claves",+ loadMoreKeysHint: "Escanea otro lote de claves y añádelo al final de la lista. Las claves ya cargadas se mantienen.",fetchAllKeys: "Cargar todas",+ fetchAllKeysHint: "Termina de cargar las claves restantes de una vez (continúa desde la posición actual) y luego sustituye la lista con el resultado.",+ refetchAllKeys: "Recargar todas",+ allKeysLoaded: "Todas las claves cargadas",+ loadMoreAllLoadedHint: "Se escaneó toda la base de datos, no hay más claves que cargar. Usa «Recargar todas» para volver a escanearla desde el principio.",+ refetchAllKeysHint: "Vuelve a escanear toda la base de datos desde el principio y sustituye la lista actual por el resultado.",+ backfillMetadata: "Completar tipo y expiración",+ backfillMetadataPending: "Algunas claves aún no tienen tipo ni tiempo de expiración",+ backfillMetadataProgress: "Completando metadatos {loaded} / {total}",+ backfillMetadataHint: "Esta base de datos se listó por nombre de clave, sin tipo ni expiración. Puedes completarlos para todas las claves cargadas.",stopFetchAll: "Detener",+ stopFetchAllHint: "Detener abandona este escaneo: las claves recogidas no se conservan y la lista vuelve a su estado anterior.",fetchAllProgress: "{loaded} de {total} claves cargadas",fetchAllProgressUnknown: "{loaded} claves cargadas",items: "{count} elementos",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex c5537fdb55..f691d2a1b0 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -6343,8 +6343,19 @@ export default withEnglishFallback({searchingValues: "Mencari nilai...",searchingAll: "Mencari key dan nilai...",loadMoreKeys: "Muat lebih banyak key",+ loadMoreKeysHint: "Pindai satu batch key lagi dan tambahkan ke akhir daftar. Key yang sudah dimuat tetap ada.",fetchAllKeys: "Ambil semua",+ fetchAllKeysHint: "Selesaikan sisa key sekaligus (lanjutkan dari posisi saat ini), lalu ganti daftar dengan hasilnya.",+ refetchAllKeys: "Muat ulang semua",+ allKeysLoaded: "Semua key sudah dimuat",+ loadMoreAllLoadedHint: "Seluruh basis data sudah dipindai, tidak ada key lain untuk dimuat. Gunakan “Muat ulang semua” untuk memindai ulang dari awal.",+ refetchAllKeysHint: "Pindai ulang seluruh basis data dari awal dan ganti daftar saat ini dengan hasilnya.",+ backfillMetadata: "Lengkapi tipe dan kedaluwarsa",+ backfillMetadataPending: "Sebagian key masih belum punya tipe dan waktu kedaluwarsa",+ backfillMetadataProgress: "Melengkapi metadata {loaded} / {total}",+ backfillMetadataHint: "Basis data ini dimuat berdasarkan nama key, tanpa tipe dan kedaluwarsa. Bisa dilengkapi untuk semua key yang sudah dimuat.",stopFetchAll: "Hentikan",+ stopFetchAllHint: "Menghentikan membatalkan pemindaian ini: key yang terkumpul tidak disimpan dan daftar kembali ke kondisi sebelum pemindaian.",fetchAllProgress: "{loaded} dari {total} key dimuat",fetchAllProgressUnknown: "{loaded} key dimuat",items: "{count} item",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 5ca01db6db..3c405e5e00 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -6728,8 +6728,19 @@ export default withEnglishFallback({searchingValues: "Ricerca nei valori...",searchingAll: "Ricerca in chiavi e valori...",loadMoreKeys: "Carica altre chiavi",+ loadMoreKeysHint: "Scansiona un altro lotto di chiavi e aggiungilo in fondo alla lista. Le chiavi già caricate restano al loro posto.",fetchAllKeys: "Recupera tutto",+ fetchAllKeysHint: "Completa in una volta le chiavi rimanenti (proseguendo dalla posizione attuale), poi sostituisci l'elenco con il risultato.",+ refetchAllKeys: "Ricarica tutto",+ allKeysLoaded: "Tutte le chiavi caricate",+ loadMoreAllLoadedHint: "L'intero database è stato scansionato, non ci sono altre chiavi da caricare. Usa «Ricarica tutto» per scansionarlo di nuovo dall'inizio.",+ refetchAllKeysHint: "Scansiona di nuovo l'intero database dall'inizio e sostituisci l'elenco corrente con il risultato.",+ backfillMetadata: "Completa tipo e scadenza",+ backfillMetadataPending: "Alcune chiavi non hanno ancora tipo né scadenza",+ backfillMetadataProgress: "Completamento dei metadati {loaded} / {total}",+ backfillMetadataHint: "Questo database è stato elencato per nome, senza tipo né scadenza. Puoi completarli per tutte le chiavi caricate.",stopFetchAll: "Interrompi",+ stopFetchAllHint: "Interrompere annulla questa scansione: le chiavi raccolte non vengono conservate e l'elenco torna allo stato precedente.",fetchAllProgress: "{loaded} di {total} chiavi caricate",fetchAllProgressUnknown: "{loaded} chiavi caricate",items: "{count} elementi",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 2cd7d4f3f9..eda5bce648 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -6744,8 +6744,19 @@ export default withEnglishFallback({searchingAll: "キーと値を検索中...",noKeysInScanHint: "現在のスキャン範囲で一致するキーは見つかりません",loadMoreKeys: "さらにキーを読み込む",+ loadMoreKeysHint: "キーをもう 1 バッチ読み込んで一覧の末尾に追加します。読み込み済みのキーはそのまま残ります。",fetchAllKeys: "すべて取得",+ fetchAllKeysHint: "残りのキーを一度に読み込みます(現在位置から続行し)、その後一覧をその結果で置き換えます。",+ refetchAllKeys: "すべて再読み込み",+ allKeysLoaded: "すべてのキーを読み込みました",+ loadMoreAllLoadedHint: "データベース全体をスキャン済みで、これ以上読み込むキーはありません。「すべて再読み込み」で先頭からスキャンし直せます。",+ refetchAllKeysHint: "データベース全体を先頭からスキャンし直して、現在の一覧をその結果で置き換えます。",+ backfillMetadata: "型と有効期限を補完",+ backfillMetadataPending: "一部のキーは型と有効期限がまだ不明です",+ backfillMetadataProgress: "メタデータを補完中 {loaded} / {total}",+ backfillMetadataHint: "このデータベースはキー名だけで読み込まれたため、型と有効期限が取得できていません。読み込み済みのすべてのキーに対して補完できます。",stopFetchAll: "停止",+ stopFetchAllHint: "停止するとこのスキャンは破棄されます。取得済みのキーは残らず、一覧はスキャン前の状態に戻ります。",fetchAllProgress: "{loaded}/{total}キー読み込み完了",fetchAllProgressUnknown: "{loaded}キー読み込み完了",items: "{count}アイテム",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex 6d5c53a120..4d9e037e65 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -6668,8 +6668,19 @@ export default withEnglishFallback({searchingValues: "값을 검색하는 중...",searchingAll: "키와 값을 검색하는 중...",loadMoreKeys: "키 더 불러오기",+ loadMoreKeysHint: "키를 한 묶음 더 스캔해 목록 끝에 추가합니다. 이미 불러온 키는 그대로 유지됩니다.",fetchAllKeys: "모두 가져오기",+ fetchAllKeysHint: "남은 키를 한 번에 가져온 뒤(현재 위치에서 이어서) 목록을 그 결과로 교체합니다.",+ refetchAllKeys: "모두 다시 불러오기",+ allKeysLoaded: "모든 키를 불러왔습니다",+ loadMoreAllLoadedHint: "데이터베이스 전체를 스캔했으니 더 불러올 키가 없습니다. “모두 다시 불러오기”로 처음부터 다시 스캔할 수 있습니다.",+ refetchAllKeysHint: "데이터베이스 전체를 처음부터 다시 스캔하고 현재 목록을 그 결과로 교체합니다.",+ backfillMetadata: "유형과 만료 시간 채우기",+ backfillMetadataPending: "일부 키의 유형과 만료 시간이 아직 없습니다",+ backfillMetadataProgress: "메타데이터 채우는 중 {loaded} / {total}",+ backfillMetadataHint: "이 데이터베이스는 키 이름으로만 불러와져 유형과 만료 시간이 없습니다. 불러온 모든 키에 대해 채울 수 있습니다.",stopFetchAll: "중지",+ stopFetchAllHint: "중지하면 이번 스캔은 취소됩니다. 모아 둔 키는 유지되지 않고 목록은 스캔 전 상태로 돌아갑니다.",fetchAllProgress: "{total}개 중 {loaded}개 키 로드됨",fetchAllProgressUnknown: "키 {loaded}개 로드됨",items: "{count}개 항목",diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.tsindex a47963b7a1..0a2f08ac5a 100644--- a/apps/desktop/src/i18n/locales/pl.ts+++ b/apps/desktop/src/i18n/locales/pl.ts@@ -6369,8 +6369,19 @@ export default withEnglishFallback({searchingValues: "Wyszukiwanie wartości...",searchingAll: "Wyszukiwanie kluczy i wartości...",loadMoreKeys: "Wczytaj więcej kluczy",+ loadMoreKeysHint: "Skanuje kolejną partię kluczy i dopisuje ją na końcu listy. Już wczytane klucze zostają bez zmian.",fetchAllKeys: "Pobierz wszystkie",+ fetchAllKeysHint: "Kończy ładowanie pozostałych kluczy w jednym przejściu (kontynuując od bieżącego miejsca), a następnie zastępuje listę wynikiem.",+ refetchAllKeys: "Wczytaj wszystko ponownie",+ allKeysLoaded: "Wszystkie klucze wczytane",+ loadMoreAllLoadedHint: "Cała baza została zeskanowana, nie ma więcej kluczy do wczytania. Użyj „Wczytaj wszystko ponownie”, aby przeskanować ją od nowa.",+ refetchAllKeysHint: "Ponownie skanuje całą bazę od początku i zastępuje bieżącą listę wynikiem.",+ backfillMetadata: "Uzupełnij typ i wygaśnięcie",+ backfillMetadataPending: "Część kluczy nie ma jeszcze typu ani czasu wygaśnięcia",+ backfillMetadataProgress: "Uzupełnianie metadanych {loaded} / {total}",+ backfillMetadataHint: "Ta baza została wczytana po nazwach kluczy, bez typu i wygaśnięcia. Możesz je uzupełnić dla wszystkich wczytanych kluczy.",stopFetchAll: "Zatrzymaj",+ stopFetchAllHint: "Zatrzymanie porzuca to skanowanie: zebrane klucze nie zostają zachowane, a lista wraca do stanu sprzed skanowania.",fetchAllProgress: "Wczytano {loaded} z {total} kluczy",fetchAllProgressUnknown: "Wczytano {loaded} kluczy",items: "Elementy: {count}",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex a72d1976a5..e43134cc61 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -6726,8 +6726,19 @@ export default withEnglishFallback({searchingValues: "Pesquisando valores...",searchingAll: "Pesquisando chaves e valores...",loadMoreKeys: "Carregar mais chaves",+ loadMoreKeysHint: "Varre mais um lote de chaves e adiciona ao final da lista. As chaves já carregadas permanecem.",fetchAllKeys: "Buscar todas",+ fetchAllKeysHint: "Conclui as chaves restantes de uma vez (continuando da posição atual) e depois substitui a lista pelo resultado.",+ refetchAllKeys: "Recarregar todas",+ allKeysLoaded: "Todas as chaves carregadas",+ loadMoreAllLoadedHint: "O banco de dados inteiro foi varrido, não há mais chaves para carregar. Use “Recarregar todas” para varrer tudo de novo do início.",+ refetchAllKeysHint: "Varre o banco de dados inteiro de novo do início e substitui a lista atual pelo resultado.",+ backfillMetadata: "Preencher tipo e expiração",+ backfillMetadataPending: "Algumas chaves ainda estão sem tipo e sem expiração",+ backfillMetadataProgress: "Preenchendo metadados {loaded} / {total}",+ backfillMetadataHint: "Este banco de dados foi listado apenas pelo nome da chave, sem tipo e expiração. Você pode preencher para todas as chaves carregadas.",stopFetchAll: "Parar",+ stopFetchAllHint: "Parar descarta esta varredura: as chaves coletadas não são mantidas e a lista volta ao estado anterior à varredura.",fetchAllProgress: "{loaded} de {total} chaves carregadas",fetchAllProgressUnknown: "{loaded} chaves carregadas",items: "{count} itens",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 6159afe374..7630272d25 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -7996,8 +7996,19 @@ export default withEnglishFallback({searchingValues: "Поиск по значениям...",searchingAll: "Поиск по ключам и значениям...",loadMoreKeys: "Загрузить ещё ключи",+ loadMoreKeysHint: "Сканирует ещё одну партию ключей и добавляет её в конец списка. Уже загруженные ключи остаются на месте.",fetchAllKeys: "Загрузить все",+ fetchAllKeysHint: "Завершает загрузку оставшихся ключей за один проход (продолжая с текущей позиции), затем заменяет список результатом.",+ refetchAllKeys: "Загрузить все заново",+ allKeysLoaded: "Все ключи загружены",+ loadMoreAllLoadedHint: "Вся база просканирована, загружать больше нечего. Нажмите «Загрузить все заново», чтобы просканировать её с начала.",+ refetchAllKeysHint: "Сканирует всю базу заново с начала и заменяет текущий список результатом.",+ backfillMetadata: "Заполнить тип и срок действия",+ backfillMetadataPending: "У некоторых ключей пока нет типа и срока действия",+ backfillMetadataProgress: "Заполнение метаданных {loaded} / {total}",+ backfillMetadataHint: "Эта база была загружена только по именам ключей, без типа и срока действия. Их можно заполнить для всех загруженных ключей.",stopFetchAll: "Остановить",+ stopFetchAllHint: "Остановка прерывает это сканирование: собранные ключи не сохраняются, а список возвращается к состоянию до сканирования.",fetchAllProgress: "Загружено {loaded} из {total} ключей",fetchAllProgressUnknown: "Загружено {loaded} ключей",items: "{count} элементов",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex 01b3877407..735aa49e3c 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -8255,8 +8255,19 @@ export default withEnglishFallback({searchingValues: "กำลังค้นหา Values...",searchingAll: "กำลังค้นหา Keys และ Values...",loadMoreKeys: "โหลด Keys เพิ่ม",+ loadMoreKeysHint: "สแกน Keys อีกชุดแล้วเติมต่อท้ายรายการ Keys ที่โหลดไว้แล้วจะยังคงอยู่",fetchAllKeys: "ดึงข้อมูลทั้งหมด",+ fetchAllKeysHint: "โหลด Keys ที่เหลือให้เสร็จในครั้งเดียว (ต่อจากตำแหน่งปัจจุบัน) แล้วแทนที่รายการด้วยผลลัพธ์",+ refetchAllKeys: "โหลดทั้งหมดอีกครั้ง",+ allKeysLoaded: "โหลด Keys ครบแล้ว",+ loadMoreAllLoadedHint: "สแกนฐานข้อมูลทั้งหมดแล้ว ไม่มี Keys ให้โหลดเพิ่ม กด「โหลดทั้งหมดอีกครั้ง」เพื่อสแกนใหม่ตั้งแต่ต้น",+ refetchAllKeysHint: "สแกนฐานข้อมูลทั้งหมดใหม่ตั้งแต่ต้น แล้วแทนที่รายการปัจจุบันด้วยผลลัพธ์",+ backfillMetadata: "เติม Type และ Expiry",+ backfillMetadataPending: "บาง Keys ยังไม่มี Type และเวลา Expiry",+ backfillMetadataProgress: "กำลังเติม Metadata {loaded} / {total}",+ backfillMetadataHint: "ฐานข้อมูลนี้ถูกโหลดด้วยชื่อ Key เท่านั้น จึงไม่มี Type และ Expiry สามารถเติมให้กับทุก Key ที่โหลดไว้ได้",stopFetchAll: "หยุด",+ stopFetchAllHint: "การหยุดจะยกเลิกการสแกนครั้งนี้ Keys ที่เก็บมาไม่ถูกเก็บไว้ และรายการจะกลับไปเป็นสถานะก่อนสแกน",fetchAllProgress: "โหลด Keys แล้ว {loaded} จาก {total}",fetchAllProgressUnknown: "โหลด Keys แล้ว {loaded} รายการ",items: "Items {count} รายการ",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex 18cbf08341..481364084e 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -5572,8 +5572,19 @@ export default withEnglishFallback({searchingValues: "Değerler aranıyor...",searchingAll: "Anahtarlar ve değerler aranıyor...",loadMoreKeys: "Daha fazla anahtar yükle",+ loadMoreKeysHint: "Bir grup anahtarı daha tarar ve listenin sonuna ekler. Zaten yüklenmiş anahtarlar yerinde kalır.",fetchAllKeys: "Tümünü getir",+ fetchAllKeysHint: "Kalan anahtarları tek seferde tamamlar (mevcut konumdan devam eder) ve ardından listeyi sonuçla değiştirir.",+ refetchAllKeys: "Tümünü yeniden yükle",+ allKeysLoaded: "Tüm anahtarlar yüklendi",+ loadMoreAllLoadedHint: "Veritabanının tamamı tarandı, yüklenecek başka anahtar yok. Baştan taramak için “Tümünü yeniden yükle” düğmesini kullanın.",+ refetchAllKeysHint: "Veritabanının tamamını baştan yeniden tarar ve mevcut listeyi sonuçla değiştirir.",+ backfillMetadata: "Türü ve sona erme süresini doldur",+ backfillMetadataPending: "Bazı anahtarların türü ve sona erme süresi hâlâ bilinmiyor",+ backfillMetadataProgress: "Meta veri dolduruluyor {loaded} / {total}",+ backfillMetadataHint: "Bu veritabanı yalnızca anahtar adlarıyla yüklendiği için tür ve sona erme bilgisi yok. Yüklenen tüm anahtarlar için doldurabilirsiniz.",stopFetchAll: "Durdur",+ stopFetchAllHint: "Durdurmak bu taramayı iptal eder: toplanan anahtarlar saklanmaz ve liste tarama öncesi hâline döner.",fetchAllProgress: "{total} anahtarın {loaded} tanesi yüklendi",fetchAllProgressUnknown: "{loaded} anahtar yüklendi",items: "{count} öğe",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 388aa4bac2..ba36193ecb 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -7850,8 +7850,19 @@ export default withEnglishFallback({searchingValues: "正在按值搜索...",searchingAll: "正在搜索 key 和值...",loadMoreKeys: "加载更多",- fetchAllKeys: "获取全部",- stopFetchAll: "停止",+ loadMoreKeysHint: "再扫描一批 key 追加到列表末尾,已加载的内容不变。",+ fetchAllKeys: "加载全部",+ fetchAllKeysHint: "一次扫完剩余的 key(从当前进度继续),完成后用新结果替换列表。",+ refetchAllKeys: "重新加载全部",+ allKeysLoaded: "已全部加载",+ loadMoreAllLoadedHint: "整个库已扫完,没有更多可加载。点“重新加载全部”可以从头再扫一遍。",+ refetchAllKeysHint: "从头重新扫描整个库,并用新结果替换当前列表。",+ backfillMetadata: "补齐类型与过期",+ backfillMetadataPending: "部分 key 还缺少类型和过期时间",+ backfillMetadataProgress: "正在补齐 {loaded} / {total}",+ backfillMetadataHint: "这个库是按键名加载的,没有取类型和过期时间,可为全部已加载的 key 补齐。",+ stopFetchAll: "停止扫描",+ stopFetchAllHint: "停止后放弃本次扫描,已扫到的 key 不会保留,列表回到扫描前。",fetchAllProgress: "已加载 {loaded} / 共 {total} 条 key",fetchAllProgressUnknown: "已加载 {loaded} 条 key",items: "{count} 个元素",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex fd7010535a..f086cf0942 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -5839,8 +5839,19 @@ export default withEnglishFallback({searchingValues: "正在按值搜尋……",searchingAll: "正在搜尋鍵和值……",loadMoreKeys: "載入更多",+ loadMoreKeysHint: "再掃描一批 Key 追加到清單末尾,已載入的內容不變。",fetchAllKeys: "取得全部",+ fetchAllKeysHint: "一次掃完剩餘的 Key(從目前進度繼續),完成後用新結果取代清單。",+ refetchAllKeys: "重新載入全部",+ allKeysLoaded: "已全部載入",+ loadMoreAllLoadedHint: "整個資料庫已掃完,沒有更多可載入的 Key。點「重新載入全部」可以從頭再掃一遍。",+ refetchAllKeysHint: "從頭重新掃描整個資料庫,並用新結果取代目前的清單。",+ backfillMetadata: "補齊型別與到期時間",+ backfillMetadataPending: "部分 Key 還缺少型別與到期時間",+ backfillMetadataProgress: "正在補齊 {loaded} / {total}",+ backfillMetadataHint: "這個資料庫是按 Key 名稱載入的,沒有取得型別與到期時間,可為全部已載入的 Key 補齊。",stopFetchAll: "停止",+ stopFetchAllHint: "停止後會放棄這次掃描,已掃到的 Key 不會保留,清單回到掃描前。",fetchAllProgress: "已載入 {loaded} / 共 {total} 條 key",fetchAllProgressUnknown: "已載入 {loaded} 條 key",items: "{count} 個元素",diff --git a/apps/desktop/src/lib/__tests__/redis/redisKeyMetadata.spec.ts b/apps/desktop/src/lib/__tests__/redis/redisKeyMetadata.spec.tsnew file mode 100644index 0000000000..e9b5a297ea--- /dev/null+++ b/apps/desktop/src/lib/__tests__/redis/redisKeyMetadata.spec.ts@@ -0,0 +1,45 @@+import { describe, expect, it } from "vitest";+import { REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS, REDIS_FETCH_ALL_SCAN_COUNT, REDIS_METADATA_BACKFILL_QUEUE_LIMIT, redisFetchAllShouldInlineMetadata, trimRedisMetadataBackfillQueue } from "@/lib/redis/redisKeyMetadata";++describe("Redis key metadata budget", () => {+ it("keeps the metadata inline while the sweep stays inside the budget", () => {+ expect(redisFetchAllShouldInlineMetadata(0)).toBe(true);+ expect(redisFetchAllShouldInlineMetadata(REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS - 1)).toBe(true);+ });++ it("stops the inline metadata once the budget is used up", () => {+ expect(redisFetchAllShouldInlineMetadata(REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS)).toBe(false);+ expect(redisFetchAllShouldInlineMetadata(REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS + 1)).toBe(false);+ });++ it("matches the scan batch size so one batch cannot blow the budget up", () => {+ // The sweep asks Redis for COUNT = REDIS_FETCH_ALL_SCAN_COUNT keys per+ // round trip, so a single batch is the largest unit the budget has to+ // absorb: the first batch of a sweep is inlined unconditionally.+ expect(REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS).toBe(REDIS_FETCH_ALL_SCAN_COUNT);+ expect(REDIS_FETCH_ALL_SCAN_COUNT).toBe(50_000);+ });+});++describe("Redis key metadata backfill queue", () => {+ it("keeps the queue within its limit and drops the oldest keys first", () => {+ const queue = new Set<string>();+ for (let index = 0; index < REDIS_METADATA_BACKFILL_QUEUE_LIMIT + 10; index++) queue.add(`key:${index}`);++ trimRedisMetadataBackfillQueue(queue);++ expect(queue.size).toBe(REDIS_METADATA_BACKFILL_QUEUE_LIMIT);+ // The oldest entries are the ones that go: they belong to the rows the+ // user scrolled past.+ expect(queue.has("key:0")).toBe(false);+ expect(queue.has(`key:${REDIS_METADATA_BACKFILL_QUEUE_LIMIT + 9}`)).toBe(true);+ });++ it("leaves a queue that fits untouched", () => {+ const queue = new Set(["a", "b"]);++ trimRedisMetadataBackfillQueue(queue);++ expect([...queue]).toEqual(["a", "b"]);+ });+});diff --git a/apps/desktop/src/lib/backend/api.ts b/apps/desktop/src/lib/backend/api.tsindex f9c1b42fe9..24a516927b 100644--- a/apps/desktop/src/lib/backend/api.ts+++ b/apps/desktop/src/lib/backend/api.ts@@ -667,6 +667,7 @@ export type { DamengDumpKind, DamengDumpRequest, DamengDumpProgress } from "./daexport const redisListDatabases = forward("redisListDatabases");export const redisScanKeys = forward("redisScanKeys");export const redisScanKeysBatch = forward("redisScanKeysBatch");+export const redisKeyMetadataBatch = forward("redisKeyMetadataBatch");export const redisScanValues = forward("redisScanValues");export const redisGetValue = forward("redisGetValue");export const redisGetRawValue = forward("redisGetRawValue");@@ -1127,6 +1128,7 @@ export type {RedisDatabaseInfo,RedisHashItem,RedisKeyInfo,+ RedisKeyMetadata,RedisKeysExpiryResult,RedisListItem,RedisSetItem,diff --git a/apps/desktop/src/lib/backend/http.ts b/apps/desktop/src/lib/backend/http.tsindex a785f7b28f..4b4a39ecef 100644--- a/apps/desktop/src/lib/backend/http.ts+++ b/apps/desktop/src/lib/backend/http.ts@@ -184,6 +184,7 @@ import type {RedisValue,RedisKeysExpiryResult,RedisScanResult,+ RedisKeyMetadata,RedisCommandResult,RedisSlowlogEntry,RedisNodeEndpoint,@@ -4064,6 +4065,14 @@ export async function redisScanKeysBatch(connectionId: string, db: number, curso});}+export async function redisKeyMetadataBatch(connectionId: string, db: number, keyRaws: string[]): Promise<RedisKeyMetadata[]> {+ return post("/api/redis/key-metadata-batch", {+ connectionId,+ db,+ keyRaws,+ });+}+export async function redisScanValues(connectionId: string, db: number, cursor: number, pattern: string, query: string, count: number, includeKeyMatches = false): Promise<RedisScanResult> {return post("/api/redis/scan-values", {connectionId,diff --git a/apps/desktop/src/lib/backend/tauri.ts b/apps/desktop/src/lib/backend/tauri.tsindex 0cadad8309..3e379c7f9d 100644--- a/apps/desktop/src/lib/backend/tauri.ts+++ b/apps/desktop/src/lib/backend/tauri.ts@@ -3763,6 +3763,13 @@ export interface RedisKeyInfo {value_preview?: string;}+/** TYPE + TTL of one key, resolved for an explicit list of keys. */+export interface RedisKeyMetadata {+ key_raw: string;+ key_type?: string;+ ttl: number;+}+export interface RedisDatabaseInfo {db: number;/** 该库的键数量;服务端无法给出可信数量时(如 kvrocks 未执行过 DBSIZE SCAN)缺省。 */@@ -3940,6 +3947,14 @@ export async function redisScanKeysBatch(connectionId: string, db: number, curso});}+export async function redisKeyMetadataBatch(connectionId: string, db: number, keyRaws: string[]): Promise<RedisKeyMetadata[]> {+ return invoke("redis_key_metadata_batch", {+ connectionId,+ db,+ keyRaws,+ });+}+export async function redisScanValues(connectionId: string, db: number, cursor: number, pattern: string, query: string, count: number, includeKeyMatches = false): Promise<RedisScanResult> {return invoke("redis_scan_values", {connectionId,diff --git a/apps/desktop/src/lib/redis/__tests__/redisKeyTree.spec.ts b/apps/desktop/src/lib/redis/__tests__/redisKeyTree.spec.tsnew file mode 100644index 0000000000..c3afebba3b--- /dev/null+++ b/apps/desktop/src/lib/redis/__tests__/redisKeyTree.spec.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";+import { redisKeyPassesNoExpiryFilter } from "@/lib/redis/redisKeyTree";++describe("Redis no-expiry filter membership", () => {+ it("keeps a key whose expiry is still unknown", () => {+ // The server leaves the TTL out of the payload when it did not answer+ // for the key, so an unknown expiry arrives as undefined. The -2 sentinel+ // is the same answer in its numeric form.+ expect(redisKeyPassesNoExpiryFilter({ ttl: undefined })).toBe(true);+ expect(redisKeyPassesNoExpiryFilter({ ttl: -2 })).toBe(true);+ });++ it("keeps a key that never expires", () => {+ expect(redisKeyPassesNoExpiryFilter({ ttl: -1 })).toBe(true);+ });++ it("drops a key with a real expiry", () => {+ expect(redisKeyPassesNoExpiryFilter({ ttl: 3600 })).toBe(false);+ expect(redisKeyPassesNoExpiryFilter({ ttl: 0 })).toBe(false);+ });+});diff --git a/apps/desktop/src/lib/redis/redisKeyMetadata.ts b/apps/desktop/src/lib/redis/redisKeyMetadata.tsnew file mode 100644index 0000000000..5b6534cb7d--- /dev/null+++ b/apps/desktop/src/lib/redis/redisKeyMetadata.ts@@ -0,0 +1,67 @@+/**+ * The key browser fills the TYPE badge and the expiry countdown of the rows+ * it lists. A scan can ask the server for that metadata inline, which costs+ * two commands per key, so the sweep only does it for a bounded number of+ * keys and the rest is resolved afterwards.+ */++/**+ * Keys one sweep round trip asks Redis for.+ *+ * The sweep uses large key-only SCAN pages and rebuilds the tree once at the+ * end; the per-page tree sorting dominates the runtime on million-key pattern+ * scans.+ */+export const REDIS_FETCH_ALL_SCAN_COUNT = 50_000;++/**+ * Keys a single sweep may pay for inline TYPE/TTL metadata.+ *+ * The sweep asks Redis for COUNT = REDIS_FETCH_ALL_SCAN_COUNT keys per round+ * trip, so one batch already costs at most 2 * REDIS_FETCH_ALL_SCAN_COUNT+ * commands. The budget keeps a whole sweep at that order of magnitude no+ * matter how large the keyspace is: the keys beyond it are listed by name and+ * their badges are filled in afterwards, for the rows the user actually looks+ * at.+ *+ * The budget is the page size because the first batch of a sweep is inlined+ * unconditionally: a smaller budget would only mean the sweep pays for more+ * than the budget allows.+ */+export const REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS = REDIS_FETCH_ALL_SCAN_COUNT;++/**+ * Whether the sweep may keep asking for inline TYPE/TTL metadata.+ *+ * `inlineKeys` counts the keys the sweep already asked the server about, so+ * the decision never depends on a DBSIZE that may be stale, may be missing+ * (kvrocks only counts asynchronously) or that describes the whole database+ * instead of the filtered scope being swept.+ */+export function redisFetchAllShouldInlineMetadata(inlineKeys: number, budget = REDIS_FETCH_ALL_INLINE_METADATA_MAX_KEYS): boolean {+ return inlineKeys < budget;+}++/**+ * Keys that may wait for their metadata.+ *+ * The visible window can queue faster than the backend answers, so the queue+ * is capped: it holds the rows the user is looking at, not every key of a+ * million-key database.+ */+export const REDIS_METADATA_BACKFILL_QUEUE_LIMIT = 5_000;++/**+ * Drops the oldest queued keys once the queue grows past its limit.+ *+ * The oldest entries belong to the rows the user scrolled past; their badges+ * are filled in again when they are listed anew. The queue keeps its+ * insertion order, so the first key is the oldest one.+ */+export function trimRedisMetadataBackfillQueue(queue: Set<string>, limit = REDIS_METADATA_BACKFILL_QUEUE_LIMIT): void {+ while (queue.size > limit) {+ const oldest = queue.values().next().value;+ if (oldest === undefined) break;+ queue.delete(oldest);+ }+}diff --git a/apps/desktop/src/lib/redis/redisKeyTree.ts b/apps/desktop/src/lib/redis/redisKeyTree.tsindex ebcc209f42..14b8638829 100644--- a/apps/desktop/src/lib/redis/redisKeyTree.ts+++ b/apps/desktop/src/lib/redis/redisKeyTree.ts@@ -8,6 +8,25 @@ export function canBuildRedisFuzzyTree(loadedKeyCount: number): boolean {return loadedKeyCount <= REDIS_FUZZY_TREE_MAX_KEYS;}+/**+ * Membership of the "no expiry" filter.+ *+ * An unknown expiry means the expiry is *unknown*, not "it expires": rows+ * loaded without inline metadata (the "fetch all" sweep skips TYPE/TTL for+ * large keyspaces) must stay in the projection until a metadata backfill+ * resolves them. Dropping them here would silently hide every unresolved key+ * instead of showing it as "not yet known".+ *+ * The unknown TTL arrives in two shapes and both mean the same thing: the+ * payload leaves the field out entirely (`undefined`) and the Rust side uses+ * -2 as its "no answer" sentinel. They are normalised here so the predicate+ * and the metadata backfill agree on what "unresolved" looks like.+ */+export function redisKeyPassesNoExpiryFilter(key: Pick<RedisKeyInfo, "ttl">): boolean {+ const ttl = key.ttl ?? -2;+ return ttl === -1 || ttl === -2;+}+export interface RedisKeyTreeLeafNode {kind: "leaf";id: string;@@ -349,9 +368,9 @@ export async function buildRedisKeySnapshotCooperatively(flatKeyByRaw.set(key.key_raw, key);loadedKeyRaws.add(key.key_raw);flatKeys.push(key);- if (!config.noExpiryOnly || key.ttl === -1) filteredKeyCount++;+ if (!config.noExpiryOnly || redisKeyPassesNoExpiryFilter(key)) filteredKeyCount++;if (treeState) appendRedisKeyUnsorted(treeState, key, config.db, separator);- if (filteredTreeState && key.ttl === -1) appendRedisKeyUnsorted(filteredTreeState, key, config.db, separator);+ if (filteredTreeState && redisKeyPassesNoExpiryFilter(key)) appendRedisKeyUnsorted(filteredTreeState, key, config.db, separator);}controller.recordCompleted(end - offset);}@@ -396,7 +415,7 @@ export async function buildRedisKeySnapshotCooperatively(const end = Math.min(offset + chunkSize, flatKeys.length);for (let index = offset; index < end; index++) {const key = flatKeys[index];- if (!config.noExpiryOnly || key.ttl === -1) visibleRows.push(redisKeyToFlatTreeRow(key, config.db));+ if (!config.noExpiryOnly || redisKeyPassesNoExpiryFilter(key)) visibleRows.push(redisKeyToFlatTreeRow(key, config.db));}controller.recordCompleted(end - offset);}diff --git a/crates/dbx-core/src/query/redis_ops.rs b/crates/dbx-core/src/query/redis_ops.rsindex 80a9a6c6c7..eb7668c93e 100644--- a/crates/dbx-core/src/query/redis_ops.rs+++ b/crates/dbx-core/src/query/redis_ops.rs@@ -1,7 +1,7 @@use crate::connection::{AppState, PoolKind};use crate::db::redis_driver::{- self, RedisBlob, RedisCollectionPage, RedisCommandResult, RedisConnection, RedisDatabaseInfo, RedisKeysExpiry,- RedisKeysExpiryResult, RedisScanResult, RedisStreamConsumer, RedisStreamGroup, RedisStreamPage,+ self, RedisBlob, RedisCollectionPage, RedisCommandResult, RedisConnection, RedisDatabaseInfo, RedisKeyMetadata,+ RedisKeysExpiry, RedisKeysExpiryResult, RedisScanResult, RedisStreamConsumer, RedisStreamGroup, RedisStreamPage,RedisStreamPendingPage, RedisValue,};@@ -88,6 +88,47 @@ pub async fn redis_scan_keys_batch_core(}}+/// Reads TYPE and TTL for an explicit list of keys.+///+/// The key browser lists key names without metadata when it loads a whole+/// database in one sweep. This endpoint fills the missing badges for the rows+/// that are actually shown, so the cost is proportional to the visible rows+/// instead of the keyspace.+pub async fn redis_key_metadata_batch_in_db_core(+ state: &AppState,+ connection_id: &str,+ db: u32,+ key_raws: &[String],+) -> Result<Vec<RedisKeyMetadata>, String> {+ ensure_redis_pool(state, connection_id).await?;+ let pool = state.pool_handle(connection_id).await.ok_or("Not found")?;+ let mut keys = Vec::with_capacity(key_raws.len());+ for key_raw in key_raws {+ keys.push(redis_driver::redis_key_raw_to_bytes(key_raw)?);+ }+ match &pool {+ PoolKind::Redis(redis) => match redis.as_ref() {+ RedisConnection::Direct(con) => {+ let mut con = con.lock().await;+ redis_driver::select_db(&mut *con, db).await?;+ redis_driver::key_metadata_batch(&mut *con, &keys).await+ }+ RedisConnection::Cluster(cluster) => {+ redis_driver::ensure_cluster_database(cluster, db).await?;+ // A cluster pipeline cannot span slots, so every key keeps its+ // own slot-routed connection, like `apply_redis_keys_expiry`.+ let mut result = Vec::with_capacity(keys.len());+ for key in &keys {+ let mut con = redis_driver::cluster_key_connection_in_db(cluster, key, db).await?;+ result.extend(redis_driver::key_metadata_batch(&mut con, std::slice::from_ref(key)).await?);+ }+ Ok(result)+ }+ },+ _ => Err("Not a Redis connection".to_string()),+ }+}+#[allow(clippy::too_many_arguments)]pub async fn redis_scan_values_core(state: &AppState,diff --git a/crates/dbx-driver-redis/src/lib.rs b/crates/dbx-driver-redis/src/lib.rsindex 150932f855..6053fe3849 100644--- a/crates/dbx-driver-redis/src/lib.rs+++ b/crates/dbx-driver-redis/src/lib.rs@@ -52,6 +52,14 @@ const COLLECTION_OVERFLOW_SESSION_TTL: Duration = Duration::from_secs(5 * 60);const COLLECTION_OVERFLOW_CURSOR_START: u64 = 1 << 52;const INVALID_CLUSTER_SCAN_CURSOR_ERROR: &str = "Redis cluster scan cursor is invalid or expired";const MAX_SAFE_INTEGER_CURSOR: u64 = (1 << 53) - 1;+/// Keys per packed round trip when a batch also asks for TYPE and TTL.+///+/// The scan itself may return tens of thousands of keys in one batch, but the+/// metadata pipeline is split into chunks of this size: each chunk is one+/// round trip that carries at most `2 * SCAN_METADATA_PIPELINE_CHUNK`+/// commands (one TYPE and one TTL per key, interleaved), which keeps the+/// single-threaded server responsive for the other clients of the instance.+const SCAN_METADATA_PIPELINE_CHUNK: usize = 1000;#[derive(Debug, Clone, Serialize, Deserialize)]pub struct RedisDatabaseInfo {@@ -95,6 +103,20 @@ pub struct RedisScanResult {pub total_keys: u64,}+/// Per-key metadata (type + TTL) resolved for an explicit list of keys.+///+/// The "fetch all" path scans key names without TYPE/TTL so a million-key+/// database is not hit with two extra commands per key. When the UI needs+/// those badges afterwards it asks for exactly the keys it shows, so the cost+/// stays proportional to the visible rows instead of the keyspace.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct RedisKeyMetadata {+ pub key_raw: String,+ #[serde(default, skip_serializing_if = "String::is_empty")]+ pub key_type: String,+ pub ttl: i64,+}+/// The expiration shapes the Key Browser may apply to a batch of selected keys.////// The variants mirror [`set_ttl`] and [`set_expire_at`] exactly, so a batch edit@@ -3153,6 +3175,95 @@ wherescan_keys_batch_inner(con, cursor, pattern, count, max_iterations, include_types, true).await}+/// Reads the type and the TTL of one chunk of keys with a single packed pipeline.+///+/// The pipeline interleaves TYPE and TTL, so one round trip carries at most+/// `2 * keys.len()` commands and every answer keeps the key's position.+/// A reply that cannot be parsed becomes ("unknown", -2): the key stays+/// listed, its badge simply stays unknown.+async fn read_type_and_ttl_chunk<C>(con: &mut C, keys: &[Vec<u8>]) -> Result<Vec<(String, i64)>, String>+where+ C: ConnectionLike + Send + Sync + Unpin,+{+ let mut pipeline = redis::pipe();+ for key in keys {+ pipeline.cmd("TYPE").arg(key);+ pipeline.cmd("TTL").arg(key);+ }+ let count = pipeline.len();+ let replies = con.req_packed_commands(&pipeline, 0, count).await.map_err(|error| error.to_string())?;+ if replies.len() != count {+ return Err("Redis did not return one TYPE and one TTL reply per key".to_string());+ }++ let mut metadata = Vec::with_capacity(keys.len());+ for index in 0..keys.len() {+ let key_type =+ String::from_redis_value(replies[index * 2].clone()).ok().unwrap_or_else(|| "unknown".to_string());+ let ttl = i64::from_redis_value(replies[index * 2 + 1].clone()).ok().unwrap_or(-2);+ metadata.push((key_type, ttl));+ }+ Ok(metadata)+}++/// Reads the types of one chunk of keys with a single packed pipeline.+///+/// The types are worth a round trip of their own when the combined TYPE/TTL+/// pipeline failed as a whole: one refused command (an ACL without the TTL+/// permission, for example) must not cost the whole chunk its badges.+async fn read_types_chunk<C>(con: &mut C, keys: &[Vec<u8>]) -> Vec<String>+where+ C: ConnectionLike + Send + Sync + Unpin,+{+ let mut pipeline = redis::pipe();+ for key in keys {+ pipeline.cmd("TYPE").arg(key);+ }+ let count = pipeline.len();+ let replies = match con.req_packed_commands(&pipeline, 0, count).await {+ Ok(replies) => replies,+ Err(_) => return vec!["unknown".to_string(); keys.len()],+ };+ (0..keys.len())+ .map(|index| {+ replies+ .get(index)+ .and_then(|value| String::from_redis_value(value.clone()).ok())+ .unwrap_or_else(|| "unknown".to_string())+ })+ .collect()+}++/// Reads TYPE and TTL for a batch of named keys.+///+/// This is the metadata half of `scan_keys_batch` (one packed pipeline that+/// interleaves TYPE and TTL per key) addressed by key name instead of by scan+/// cursor, so the key browser can fill the badges of rows it already listed+/// without scanning the keyspace again. A key that disappeared meanwhile+/// answers `TYPE` = "none" and `TTL` = -2.+///+/// The batch is split into chunks of `SCAN_METADATA_PIPELINE_CHUNK` keys, so+/// one round trip never carries more than `2 * SCAN_METADATA_PIPELINE_CHUNK`+/// commands. A transport error fails the whole batch; a reply that cannot be+/// parsed becomes ("unknown", -2) instead of an empty type.+pub async fn key_metadata_batch<C>(con: &mut C, keys: &[Vec<u8>]) -> Result<Vec<RedisKeyMetadata>, String>+where+ C: ConnectionLike + Send + Sync + Unpin,+{+ if keys.is_empty() {+ return Ok(Vec::new());+ }++ let mut result = Vec::with_capacity(keys.len());+ for chunk in keys.chunks(SCAN_METADATA_PIPELINE_CHUNK) {+ let chunk_metadata = read_type_and_ttl_chunk(con, chunk).await?;+ for (key, (key_type, ttl)) in chunk.iter().zip(chunk_metadata) {+ result.push(RedisKeyMetadata { key_raw: redis_key_bytes_to_raw(key), key_type, ttl });+ }+ }+ Ok(result)+}+async fn scan_keys_batch_inner<C>(con: &mut C,cursor: u64,@@ -3224,24 +3335,34 @@ whereif !keys.is_empty() {let (key_types, key_ttls): (Vec<String>, Vec<i64>) = if include_types {- let mut type_pipe = redis::pipe();- for key in &keys {- type_pipe.cmd("TYPE").arg(key);- }- let type_count = type_pipe.len();- let type_values = con.req_packed_commands(&type_pipe, 0, type_count).await.unwrap_or_default();- let key_types = type_values- .iter()- .map(|value| String::from_redis_value(value.clone()).unwrap_or_else(|_| "unknown".to_string()))- .collect();-- let mut ttl_pipe = redis::pipe();- for key in &keys {- ttl_pipe.cmd("TTL").arg(key);+ let mut key_types: Vec<String> = Vec::with_capacity(keys.len());+ let mut key_ttls: Vec<i64> = Vec::with_capacity(keys.len());+ // One packed pipeline per chunk keeps a single round trip bounded.+ // The whole batch would otherwise ask the server for tens of+ // thousands of TYPE and TTL commands at once, and Redis answers+ // them one after another on its single thread — every other+ // client of that instance waits for the whole batch.+ for chunk in keys.chunks(SCAN_METADATA_PIPELINE_CHUNK) {+ match read_type_and_ttl_chunk(con, chunk).await {+ Ok(chunk_metadata) => {+ for (key_type, ttl) in chunk_metadata {+ key_types.push(key_type);+ key_ttls.push(ttl);+ }+ }+ // Best effort: a chunk whose metadata cannot be read+ // keeps its keys listed with an unknown badge instead+ // of failing the whole scan. The types are asked for+ // on their own, because a single refused command must+ // not take the badges of the whole chunk with it.+ Err(_) => {+ for key_type in read_types_chunk(con, chunk).await {+ key_types.push(key_type);+ key_ttls.push(-2);+ }+ }+ }}- let ttl_count = ttl_pipe.len();- let ttl_values = con.req_packed_commands(&ttl_pipe, 0, ttl_count).await.unwrap_or_default();- let key_ttls = ttl_values.into_iter().map(|value| i64::from_redis_value(value).unwrap_or(-2)).collect();(key_types, key_ttls)} else {(Vec::new(), Vec::new())@@ -7214,6 +7335,22 @@ mod tests {commands.lock().unwrap().iter().filter(|packed| packed.contains(&needle)).count()}+ /// Byte offsets of every occurrence of `command` inside a packed pipeline.+ ///+ /// The offsets make the order of the commands observable, so a test can+ /// tell an interleaved pipeline (TYPE, TTL, TYPE, TTL) from a grouped one+ /// (TYPE, TYPE, TTL, TTL) that carries the same commands.+ fn command_offsets(packed: &str, command: &str) -> Vec<usize> {+ let needle = format!("\r\n{command}\r\n");+ let mut offsets = Vec::new();+ let mut start = 0;+ while let Some(index) = packed[start..].find(&needle) {+ offsets.push(start + index);+ start += index + needle.len();+ }+ offsets+ }+fn bulk(value: &str) -> RedisRawValue {RedisRawValue::BulkString(value.as_bytes().to_vec())}@@ -9265,12 +9402,15 @@ mod tests {#[tokio::test]async fn scan_keys_batch_batches_type_and_ttl_metadata() {+ // The fake connection answers a packed pipeline in the order the+ // commands were sent, so the replies follow the interleaved order+ // TYPE, TTL, TYPE, TTL.let mut con = FakeRedisConnection::new(vec![RedisRawValue::Int(2),scan_response("0", vec!["session:a", "cache:b"]),RedisRawValue::SimpleString("string".to_string()),- RedisRawValue::SimpleString("hash".to_string()),RedisRawValue::Int(-1),+ RedisRawValue::SimpleString("hash".to_string()),RedisRawValue::Int(3600),]);@@ -9281,12 +9421,60 @@ mod tests {assert_eq!(result.keys[0].ttl, -1);assert_eq!(result.keys[1].key_type, "hash");assert_eq!(result.keys[1].ttl, 3600);- let type_pipeline = con.commands.iter().find(|packed| packed.contains("\r\nTYPE\r\n")).unwrap();- let ttl_pipeline = con.commands.iter().find(|packed| packed.contains("\r\nTTL\r\n")).unwrap();- assert_eq!(type_pipeline.matches("\r\nTYPE\r\n").count(), 2);- assert_eq!(type_pipeline.matches("\r\nTTL\r\n").count(), 0);- assert_eq!(ttl_pipeline.matches("\r\nTYPE\r\n").count(), 0);- assert_eq!(ttl_pipeline.matches("\r\nTTL\r\n").count(), 2);++ // One pipeline carries the metadata of the whole batch: two TYPE and+ // two TTL commands, interleaved in that very order.+ let metadata_pipelines: Vec<&String> =+ con.commands.iter().filter(|packed| packed.contains("\r\nTYPE\r\n")).collect();+ assert_eq!(metadata_pipelines.len(), 1);+ let packed = metadata_pipelines[0];+ let type_offsets = command_offsets(packed, "TYPE");+ let ttl_offsets = command_offsets(packed, "TTL");+ assert_eq!(type_offsets.len(), 2);+ assert_eq!(ttl_offsets.len(), 2);+ assert!(type_offsets[0] < ttl_offsets[0]);+ assert!(ttl_offsets[0] < type_offsets[1]);+ assert!(type_offsets[1] < ttl_offsets[1]);+ }++ #[tokio::test]+ async fn scan_keys_batch_splits_the_metadata_pipeline_into_bounded_chunks() {+ let chunk = super::SCAN_METADATA_PIPELINE_CHUNK;+ let key_count = chunk + 1;+ let key_names: Vec<String> = (0..key_count).map(|index| format!("key:{index}")).collect();+ let key_refs: Vec<&str> = key_names.iter().map(|name| name.as_str()).collect();++ let mut responses = vec![RedisRawValue::Int(key_count as i64), scan_response("0", key_refs)];+ // The first chunk answers with interleaved TYPE and TTL replies.+ for _ in 0..chunk {+ responses.push(RedisRawValue::SimpleString("string".to_string()));+ responses.push(RedisRawValue::Int(60));+ }+ // The tail chunk holds the single remaining key.+ responses.push(RedisRawValue::SimpleString("hash".to_string()));+ responses.push(RedisRawValue::Int(30));++ let mut con = FakeRedisConnection::new(responses);+ let result = super::scan_keys_batch(&mut con, 0, "*", 1000, 1, true).await.unwrap();++ assert_eq!(result.keys.len(), key_count);+ // Every key keeps its own metadata even though the pipeline was split.+ assert_eq!(result.keys[0].key_type, "string");+ assert_eq!(result.keys[0].ttl, 60);+ assert_eq!(result.keys[chunk - 1].key_type, "string");+ assert_eq!(result.keys[chunk - 1].ttl, 60);+ assert_eq!(result.keys[chunk].key_type, "hash");+ assert_eq!(result.keys[chunk].ttl, 30);++ // The metadata never travels in one oversized round trip: every packed+ // command carries at most one chunk worth of TYPE and TTL commands.+ let type_pipelines: Vec<&String> =+ con.commands.iter().filter(|packed| packed.contains("\r\nTYPE\r\n")).collect();+ assert_eq!(type_pipelines.len(), 2);+ assert_eq!(command_offsets(type_pipelines[0], "TYPE").len(), chunk);+ assert_eq!(command_offsets(type_pipelines[0], "TTL").len(), chunk);+ assert_eq!(command_offsets(type_pipelines[1], "TYPE").len(), 1);+ assert_eq!(command_offsets(type_pipelines[1], "TTL").len(), 1);}#[tokio::test]@@ -9295,8 +9483,8 @@ mod tests {RedisRawValue::Int(2),scan_response("0", vec!["session:a", "cache:b"]),RedisRawValue::SimpleString("string".to_string()),- RedisRawValue::SimpleString("hash".to_string()),redis::parse_redis_value(b"-NOPERM this user has no permissions to run the 'ttl' command\r\n").unwrap(),+ RedisRawValue::SimpleString("hash".to_string()),RedisRawValue::Int(3600),]);@@ -9309,6 +9497,29 @@ mod tests {assert_eq!(result.keys[1].ttl, 3600);}+ #[tokio::test]+ async fn scan_keys_batch_keeps_the_types_when_the_metadata_pipeline_fails_as_a_whole() {+ // The combined TYPE/TTL pipeline is refused as a whole, for example by+ // an ACL without the TTL permission. The types are asked for on their+ // own, so the chunk does not lose its badges with the expiry.+ let mut con = FakeRedisConnection::with_results(vec![+ Ok(RedisRawValue::Int(2)),+ Ok(scan_response("0", vec!["session:a", "cache:b"])),+ Err(noperm("ttl")),+ Ok(RedisRawValue::SimpleString("string".to_string())),+ Ok(RedisRawValue::SimpleString("hash".to_string())),+ ]);++ let result = super::scan_keys_batch(&mut con, 0, "*", 100, 1, true).await.unwrap();++ assert_eq!(result.keys.len(), 2);+ assert_eq!(result.keys[0].key_type, "string");+ assert_eq!(result.keys[1].key_type, "hash");+ // The expiry stays unknown, so the browser fills it in afterwards.+ assert_eq!(result.keys[0].ttl, -2);+ assert_eq!(result.keys[1].ttl, -2);+ }+#[tokio::test]async fn scan_keys_batch_skips_type_and_ttl_when_metadata_disabled() {// include_types=false 是“加载全部”的百万 key 链路,不能多发出任何 TYPE/TTL 命令@@ -9323,6 +9534,111 @@ mod tests {assert_eq!(con.command_count("TTL"), 0);}+ #[tokio::test]+ async fn key_metadata_batch_reads_type_and_ttl_for_the_given_keys() {+ // The fake connection answers a packed pipeline in the order the+ // commands were sent, so the replies follow the interleaved order+ // TYPE, TTL, TYPE, TTL.+ let mut con = FakeRedisConnection::new(vec![+ RedisRawValue::SimpleString("string".to_string()),+ RedisRawValue::Int(3600),+ RedisRawValue::SimpleString("hash".to_string()),+ RedisRawValue::Int(-1),+ ]);++ let result = super::key_metadata_batch(&mut con, &[b"session:a".to_vec(), b"cache:b".to_vec()]).await.unwrap();++ assert_eq!(result.len(), 2);+ assert_eq!(result[0].key_raw, super::redis_key_bytes_to_raw(b"session:a"));+ assert_eq!(result[0].key_type, "string");+ assert_eq!(result[0].ttl, 3600);+ assert_eq!(result[1].key_type, "hash");+ assert_eq!(result[1].ttl, -1);+ // The whole batch travels in one pipeline: one TYPE and one TTL per key.+ assert_eq!(con.commands.len(), 1);+ let packed = &con.commands[0];+ let type_offsets = command_offsets(packed, "TYPE");+ let ttl_offsets = command_offsets(packed, "TTL");+ assert_eq!(type_offsets.len(), 2);+ assert_eq!(ttl_offsets.len(), 2);+ assert!(type_offsets[0] < ttl_offsets[0]);+ assert!(ttl_offsets[0] < type_offsets[1]);+ assert!(type_offsets[1] < ttl_offsets[1]);+ }++ #[tokio::test]+ async fn key_metadata_batch_splits_the_metadata_pipeline_into_bounded_chunks() {+ let chunk = super::SCAN_METADATA_PIPELINE_CHUNK;+ let key_count = chunk + 1;+ let keys: Vec<Vec<u8>> = (0..key_count).map(|index| format!("key:{index}").into_bytes()).collect();++ // Every key answers with its own type and its own expiry, so a reply+ // that drifted to another key would be visible in the result.+ let mut responses = Vec::with_capacity(key_count * 2);+ for index in 0..key_count {+ let key_type = if index % 2 == 0 { "string" } else { "hash" };+ responses.push(RedisRawValue::SimpleString(key_type.to_string()));+ responses.push(RedisRawValue::Int(index as i64));+ }++ let mut con = FakeRedisConnection::new(responses);+ let result = super::key_metadata_batch(&mut con, &keys).await.unwrap();++ assert_eq!(result.len(), key_count);+ for (index, metadata) in result.iter().enumerate() {+ let expected_type = if index % 2 == 0 { "string" } else { "hash" };+ assert_eq!(metadata.key_type, expected_type);+ assert_eq!(metadata.ttl, index as i64);+ }++ // The metadata never travels in one oversized round trip: every packed+ // command carries at most one chunk worth of TYPE and TTL commands.+ let type_pipelines: Vec<&String> =+ con.commands.iter().filter(|packed| packed.contains("\r\nTYPE\r\n")).collect();+ assert_eq!(type_pipelines.len(), 2);+ assert_eq!(command_offsets(type_pipelines[0], "TYPE").len(), chunk);+ assert_eq!(command_offsets(type_pipelines[0], "TTL").len(), chunk);+ assert_eq!(command_offsets(type_pipelines[1], "TYPE").len(), 1);+ assert_eq!(command_offsets(type_pipelines[1], "TTL").len(), 1);+ }++ #[tokio::test]+ async fn key_metadata_batch_answers_unknown_type_when_the_reply_cannot_be_parsed() {+ // A TYPE reply that is not a string cannot be read as a type: the key+ // stays listed with the same "unknown" badge the scan path uses.+ let mut con = FakeRedisConnection::new(vec![RedisRawValue::Nil, RedisRawValue::Int(60)]);++ let result = super::key_metadata_batch(&mut con, &[b"session:a".to_vec()]).await.unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].key_type, "unknown");+ assert_eq!(result[0].ttl, 60);+ }++ #[tokio::test]+ async fn key_metadata_batch_answers_unknown_expiry_for_a_vanished_key() {+ // "none" is a readable answer: the key does not exist any more, which+ // is not the same as an answer that cannot be parsed.+ let mut con =+ FakeRedisConnection::new(vec![RedisRawValue::SimpleString("none".to_string()), RedisRawValue::Int(-2)]);++ let result = super::key_metadata_batch(&mut con, &[b"gone".to_vec()]).await.unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].key_type, "none");+ assert_eq!(result[0].ttl, -2);+ }++ #[tokio::test]+ async fn key_metadata_batch_without_keys_issues_no_command() {+ let mut con = FakeRedisConnection::new(vec![]);++ let result = super::key_metadata_batch(&mut con, &[]).await.unwrap();++ assert!(result.is_empty());+ assert!(con.commands.is_empty());+ }+#[tokio::test]async fn scan_keys_batch_exact_match_returns_ttl() {let mut con = FakeRedisConnection::new(vec![diff --git a/crates/dbx-web/src/main.rs b/crates/dbx-web/src/main.rsindex 7c62c0adf4..0d89b49cfe 100644--- a/crates/dbx-web/src/main.rs+++ b/crates/dbx-web/src/main.rs@@ -1015,6 +1015,7 @@ async fn serve() -> Result<(), String> {.route("/redis/list-databases", post(routes::redis::list_databases)).route("/redis/scan-keys", post(routes::redis::scan_keys)).route("/redis/scan-keys-batch", post(routes::redis::scan_keys_batch))+ .route("/redis/key-metadata-batch", post(routes::redis::key_metadata_batch)).route("/redis/scan-values", post(routes::redis::scan_values)).route("/redis/get-value", post(routes::redis::get_value)).route("/redis/get-raw-value", post(routes::redis::get_raw_value))diff --git a/crates/dbx-web/src/routes/redis.rs b/crates/dbx-web/src/routes/redis.rsindex 33823b01ef..56ea9ec535 100644--- a/crates/dbx-web/src/routes/redis.rs+++ b/crates/dbx-web/src/routes/redis.rs@@ -7,7 +7,7 @@ use serde::Deserialize;use crate::error::AppError;use crate::state::WebState;-use dbx_core::db::redis_driver::RedisKeysExpiryResult;+use dbx_core::db::redis_driver::{RedisKeyMetadata, RedisKeysExpiryResult};/// Check if a connection is read-only and return an error if so.async fn ensure_writable(@@ -282,6 +282,14 @@ pub struct RedisKeysTtlRequest {pub ttl: i64,}+#[derive(Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct RedisKeyMetadataBatchRequest {+ pub connection_id: String,+ pub db: u32,+ pub key_raws: Vec<String>,+}+#[derive(Deserialize)]#[serde(rename_all = "camelCase")]pub struct RedisKeysExpireAtRequest {@@ -847,6 +855,17 @@ pub async fn set_expire_at(Ok(Json(()))}+pub async fn key_metadata_batch(+ State(state): State<Arc<WebState>>,+ Json(req): Json<RedisKeyMetadataBatchRequest>,+) -> Result<Json<Vec<RedisKeyMetadata>>, AppError> {+ let result =+ dbx_core::redis_ops::redis_key_metadata_batch_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raws)+ .await+ .map_err(AppError::from)?;+ Ok(Json(result))+}+pub async fn set_keys_ttl(State(state): State<Arc<WebState>>,Json(req): Json<RedisKeysTtlRequest>,diff --git a/src-tauri/src/commands/redis_cmd.rs b/src-tauri/src/commands/redis_cmd.rsindex 62e3bde8b1..7d8b0f48df 100644--- a/src-tauri/src/commands/redis_cmd.rs+++ b/src-tauri/src/commands/redis_cmd.rs@@ -4,8 +4,8 @@ use tauri::State;use crate::commands::connection::{ensure_connection_writable, AppState};use dbx_core::db::redis_driver::{classify_command, parse_command_argv, RedisBlob, RedisCollectionPage, RedisCommandResult, RedisCommandSafety,- RedisDatabaseInfo, RedisKeysExpiryResult, RedisScanResult, RedisStreamConsumer, RedisStreamGroup, RedisStreamPage,- RedisStreamPendingPage, RedisValue,+ RedisDatabaseInfo, RedisKeyMetadata, RedisKeysExpiryResult, RedisScanResult, RedisStreamConsumer, RedisStreamGroup,+ RedisStreamPage, RedisStreamPendingPage, RedisValue,};#[tauri::command]@@ -52,6 +52,18 @@ pub async fn redis_scan_keys_batch(.await}+/// Reads TYPE and TTL for an explicit list of keys so the key browser can+/// fill the badges of rows it already listed without rescanning the keyspace.+#[tauri::command]+pub async fn redis_key_metadata_batch(+ state: State<'_, Arc<AppState>>,+ connection_id: String,+ db: u32,+ key_raws: Vec<String>,+) -> Result<Vec<RedisKeyMetadata>, String> {+ dbx_core::redis_ops::redis_key_metadata_batch_in_db_core(&state, &connection_id, db, &key_raws).await+}+#[tauri::command]#[allow(clippy::too_many_arguments)]pub async fn redis_scan_values(diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex b71cb6b0e2..8dc63b4db3 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -2691,6 +2691,7 @@ pub fn run() {commands::redis_cmd::redis_list_databases,commands::redis_cmd::redis_scan_keys,commands::redis_cmd::redis_scan_keys_batch,+ commands::redis_cmd::redis_key_metadata_batch,commands::redis_cmd::redis_scan_values,commands::redis_cmd::redis_get_value,commands::redis_cmd::redis_get_raw_value,