fix(redis): invalidate key completion cache after write commands

The Redis key-name completion cache was only cleared on connection
lifecycle events, so SET/DEL/EXPIRE/... left autocomplete showing
stale keys. Drop the cache for the db each write command ran on:
- add isRedisMutatingCommand() based on the command-table safety field
(confirm = write; destructive blocked cmds minus read-only/admin ones)
- invalidate after each mutating command in queryStore batch execution
and in RedisKeyBrowser.runRedisCommand
This commit is contained in:
haipengno1 authored and GitHub committed 2026-06-17 00:24:47 +08:00
1 parent 3752c9086e
commit 3695042c8e
5 files changed
+153

No files matched your search

@@ -23,6 +23,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { buildRedisKeyTree, collectExpandedGroupIds, collectRedisGroupKeyRaws, flattenVisibleRedisKeyTree, mergeKeysIntoRedisKeyTree, type RedisKeyTreeNode } from "@/lib/redisKeyTree";
import { classifyRedisCommandSafety } from "@/lib/redisCommandSafety";
import { isRedisMutatingCommand } from "@/lib/redisCommandTable";
import { isRedisClearScreenCommand, nextRedisCommandDb, redisKeyTextToRaw } from "@/lib/redisCommandSession";
import { formatRedisCommandResult, formatRedisStringValue } from "@/lib/redisValuePresentation";
import { isCancelSearchShortcut } from "@/lib/keyboardShortcuts";
@@ -436,10 +437,17 @@ async function runRedisCommand(command: string) {
output: formatRedisCommandResult(result.value),
error: false,
});
// The db this command ran on — capture before nextRedisCommandDb() advances it.
const executedDb = commandDb.value;
commandDb.value = nextRedisCommandDb(commandDb.value, command, result.value);
if (result.safety === "confirm") {
await loadKeys();
}
// Drop the cached key-name completion for this db so the editor's autocomplete
// reflects keys added/removed/renamed by SET/DEL/RENAME/...
if (isRedisMutatingCommand(command)) {
connectionStore.invalidateCompletionCache(props.connectionId, String(executedDb));
}
// Persist to history
persistRedisHistory(command, true, result.value);
} catch (error) {