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

@@ -2791,6 +2791,7 @@ export const useConnectionStore = defineStore("connection", () => {
refreshCompletionDatabases,
listElasticsearchCompletionIndices,
listRedisCompletionKeys,
invalidateCompletionCache,
exportConnectionsToFile,
readImportFile,
importConnectionsFromFile,
+6
View File
@@ -24,6 +24,7 @@ import {
} from "@/lib/mongoShellCommand";
import { redisCommandResultToQueryResult } from "@/lib/redisQueryResult";
import { nextRedisCommandDb } from "@/lib/redisCommandSession";
import { isRedisMutatingCommand } from "@/lib/redisCommandTable";
import { supportsDatabaseFeature } from "@/lib/databaseCapabilities";
import { editablePrimaryKeys } from "@/lib/tableEditing";
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/tableDataExport";
@@ -1202,6 +1203,11 @@ export const useQueryStore = defineStore("query", () => {
allResults.push(markQueryResultRowsRaw(redisCommandResultToQueryResult(result.value, performance.now() - startedAt, result.command)));
// Track db switches from SELECT N so later commands in the same batch run on the right db.
currentDb = nextRedisCommandDb(currentDb, command, result.value);
// Write commands (SET/DEL/...) mutate the key set — drop the cached key-name completion
// for the db this command ran on so the next autocomplete fetch reflects the new keys.
if (isRedisMutatingCommand(command)) {
connStore.invalidateCompletionCache(tab.connectionId, String(currentDb));
}
} catch (e: any) {
allResults.push({ columns: ["Error"], rows: [[e?.message ?? String(e)]], affected_rows: 0, execution_time_ms: 0 });
}