fix(redis): refresh sidebar db key counts after write commands

Redis write commands (SET/DEL/...) ran from the query editor or the
key-browser terminal did not update the dbN (count) labels in the left
tree until a manual refresh. Add refreshRedisDbKeyCounts(), which re-fetches
authoritative per-db counts via INFO keyspace and patches the labels in place
without rebuilding the tree (preserving expanded key nodes), then trigger it
fire-and-forget after any mutating command in both execution paths.
This commit is contained in:
haipengno1 authored and GitHub committed 2026-06-17 10:35:01 +08:00
1 parent b2617039fa
commit b575ec2729
3 files changed
+30

No files matched your search

+8
View File
@@ -1197,6 +1197,7 @@ export const useQueryStore = defineStore("query", () => {
const allResults: QueryResult[] = [];
const skipSafety = options?.skipRedisSafetyCheck;
let hadMutatingCommand = false;
for (const command of commands) {
try {
const result = await api.redisExecuteCommand(tab.connectionId, currentDb, command, skipSafety);
@@ -1206,6 +1207,7 @@ export const useQueryStore = defineStore("query", () => {
// 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)) {
hadMutatingCommand = true;
connStore.invalidateCompletionCache(tab.connectionId, String(currentDb));
}
} catch (e: any) {
@@ -1241,6 +1243,12 @@ export const useQueryStore = defineStore("query", () => {
current.database = String(currentDb);
}
}
// Refresh the sidebar db key counts (INFO keyspace) when at least one command in
// this batch mutated the key set, so `dbN (count)` stays accurate without a manual
// refresh. Fire-and-forget: never block result display.
if (hadMutatingCommand) {
void connStore.refreshRedisDbKeyCounts(tab.connectionId);
}
return;
}