feat(redis): batch key expiry updates

This commit is contained in:
jearhe authored and GitHub committed 2026-09-12 09:28:40 +08:00
1 parent 076c39bc21
commit 774f175c33
36 files changed
+1185 -20

No files matched your search

@@ -17,6 +17,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -45,6 +47,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -19,6 +19,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -58,6 +60,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -491,6 +495,8 @@ function resetApiMocks() {
mocks.redisStreamAdd.mockResolvedValue(undefined);
mocks.redisSetTtl.mockResolvedValue(undefined);
mocks.redisSetExpireAt.mockResolvedValue(undefined);
mocks.redisSetKeysTtl.mockResolvedValue({ applied: 0, missing_key_raws: [] });
mocks.redisSetKeysExpireAt.mockResolvedValue({ applied: 0, missing_key_raws: [] });
mocks.redisCheckJsonModule.mockResolvedValue(true);
mocks.redisDeleteKey.mockResolvedValue(undefined);
mocks.redisDeleteKeys.mockResolvedValue(0);
@@ -518,6 +524,9 @@ function mountBrowser(withDeleteDetails = false) {
redis: {
deleteGroupDetails: withDeleteDetails ? "{target}\n{count} keys" : "redis.deleteGroupDetails",
keys: "{count} keys",
batchExpirySelected: "redis.batchExpirySelected",
batchExpirySuccess: "applied {count}",
batchExpiryPartial: "applied {success} failed {failed}",
},
},
};
@@ -1353,6 +1362,198 @@ describe("RedisKeyBrowser expiry creation", () => {
});
});
describe("RedisKeyBrowser batch expiration", () => {
const batchKeys = [
{ key_display: "alpha", key_raw: "YWxwaGE=", key_type: "string", ttl: -1 },
{ key_display: "bravo", key_raw: "YnJhdm8=", key_type: "string", ttl: -1 },
];
function batchExpiryButton(): HTMLButtonElement | null {
return document.querySelector<HTMLButtonElement>("[data-redis-batch-expiry]");
}
async function openBatchExpiryDialog(rows = batchKeys) {
mocks.redisScanKeysBatch.mockResolvedValue({ cursor: 0, keys: rows, total_keys: rows.length });
mountBrowser();
await settle();
requiredElement<HTMLButtonElement>("[data-redis-select-all]").click();
await settle();
requiredElement<HTMLButtonElement>("[data-redis-batch-expiry]").click();
await settle();
}
async function applyBatchExpiry() {
requiredElement<HTMLButtonElement>("[data-redis-batch-expiry-apply]").click();
await settle();
}
function rowTtlBadge(label: string): HTMLElement | null {
return groupRow(label).querySelector<HTMLElement>("span[title]");
}
it("only offers the action for a non-empty selection and applies one TTL to every key", async () => {
mocks.redisSetKeysTtl.mockResolvedValue({ applied: 2, missing_key_raws: [] });
await openBatchExpiryDialog();
expect(document.body.textContent).toContain("redis.batchExpirySelected");
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "3600");
await applyBatchExpiry();
// One request for the whole selection, never one call per key.
expect(mocks.redisSetKeysTtl).toHaveBeenCalledTimes(1);
expect(mocks.redisSetKeysTtl).toHaveBeenCalledWith("connection", 0, ["YWxwaGE=", "YnJhdm8="], 3600);
expect(mocks.redisSetKeysExpireAt).not.toHaveBeenCalled();
expect(mocks.toast).toHaveBeenCalledWith("applied 2", 3000);
// A fully applied batch releases the selection like a completed batch delete does.
expect(document.querySelector("[data-redis-batch-delete]")).toBeNull();
expect(document.querySelector("[data-test-dialog]")).toBeNull();
});
it("applies PERSIST to every selected key when no expiry is chosen", async () => {
mocks.redisSetKeysTtl.mockResolvedValue({ applied: 2, missing_key_raws: [] });
await openBatchExpiryDialog();
await applyBatchExpiry();
expect(mocks.redisSetKeysTtl).toHaveBeenCalledWith("connection", 0, ["YWxwaGE=", "YnJhdm8="], -1);
expect(mocks.redisSetKeysExpireAt).not.toHaveBeenCalled();
});
it("applies the same absolute expiration time to every selected key", async () => {
mocks.redisSetKeysExpireAt.mockResolvedValue({ applied: 2, missing_key_raws: [] });
await openBatchExpiryDialog();
await select("at");
requiredElement<HTMLButtonElement>("[data-test-absolute-date]").click();
await settle();
await applyBatchExpiry();
const expireAt = calendarDateTimeToUnixSeconds(new CalendarDateTime(2030, 1, 2, 3, 4, 5));
expect(mocks.redisSetKeysExpireAt).toHaveBeenCalledTimes(1);
expect(mocks.redisSetKeysExpireAt).toHaveBeenCalledWith("connection", 0, ["YWxwaGE=", "YnJhdm8="], expireAt);
expect(mocks.redisSetKeysTtl).not.toHaveBeenCalled();
});
it("rejects an invalid TTL before reaching the backend and keeps the dialog open", async () => {
await openBatchExpiryDialog();
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "0");
await applyBatchExpiry();
expect(mocks.redisSetKeysTtl).not.toHaveBeenCalled();
expect(mocks.toast).toHaveBeenCalledWith("redis.expiryTtlInvalid", 3000);
expect(document.querySelector("[data-redis-batch-expiry-apply]")).not.toBeNull();
});
it("keeps only the keys the server did not update selected so they can be retried", async () => {
mocks.redisSetKeysTtl.mockResolvedValueOnce({ applied: 1, missing_key_raws: ["YnJhdm8="] });
mocks.redisSetKeysTtl.mockResolvedValueOnce({ applied: 1, missing_key_raws: [] });
await openBatchExpiryDialog();
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "3600");
await applyBatchExpiry();
expect(mocks.toast).toHaveBeenCalledWith("applied 1 failed 1", 5000);
expect(requiredElement<HTMLElement>("[data-redis-batch-delete]").textContent).toContain("1");
// Retrying only targets the key the server missed.
requiredElement<HTMLButtonElement>("[data-redis-batch-expiry]").click();
await settle();
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "120");
await applyBatchExpiry();
expect(mocks.redisSetKeysTtl).toHaveBeenNthCalledWith(2, "connection", 0, ["YnJhdm8="], 120);
expect(document.querySelector("[data-redis-batch-delete]")).toBeNull();
});
it("reports a failed chunk together with the keys an earlier chunk already updated", async () => {
mocks.redisSetKeysTtl.mockResolvedValueOnce({ applied: 1_000, missing_key_raws: [] });
mocks.redisSetKeysTtl.mockRejectedValueOnce(new Error("connection lost"));
const rows = Array.from({ length: 1_001 }, (_, index) => ({
key_display: `batch:${String(index).padStart(4, "0")}`,
key_raw: `cmF3LWJhdGNoLS${index}`,
key_type: "string",
ttl: -1,
}));
await openBatchExpiryDialog(rows);
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "3600");
await applyBatchExpiry();
// Bounded chunks keep a 1001-key selection to two requests.
expect(mocks.redisSetKeysTtl.mock.calls.map((call) => call[2].length)).toEqual([1_000, 1]);
expect(mocks.toast).toHaveBeenCalledWith("applied 1000 failed 1", 5000);
expect(mocks.toast).toHaveBeenCalledWith("connection lost", 5000);
expect(requiredElement<HTMLElement>("[data-redis-batch-delete]").textContent).toContain("1");
});
it("does not start a second request while the batch is still running", async () => {
const pending = deferred<{ applied: number; missing_key_raws: string[] }>();
mocks.redisSetKeysTtl.mockReturnValue(pending.promise);
await openBatchExpiryDialog();
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "3600");
const applyButton = requiredElement<HTMLButtonElement>("[data-redis-batch-expiry-apply]");
applyButton.click();
await settle();
applyButton.click();
await settle();
expect(mocks.redisSetKeysTtl).toHaveBeenCalledTimes(1);
// A conflicting batch delete stays blocked while the expiry request owns the selection.
expect(requiredElement<HTMLButtonElement>("[data-redis-batch-delete]").disabled).toBe(true);
pending.resolve({ applied: 2, missing_key_raws: [] });
await settle();
expect(mocks.toast).toHaveBeenCalledWith("applied 2", 3000);
});
it("updates the loaded TTL badge without rescanning the key list", async () => {
const rows = [{ key_display: "alpha", key_raw: "YWxwaGE=", key_type: "string", ttl: -1 }];
mocks.redisSetKeysTtl.mockResolvedValue({ applied: 1, missing_key_raws: [] });
await openBatchExpiryDialog(rows);
expect(rowTtlBadge("alpha")?.textContent).toContain("redis.noExpiry");
expect(mocks.redisScanKeysBatch).toHaveBeenCalledTimes(1);
await select("ttl");
await setInput("[data-redis-batch-expiry-ttl]", "3600");
await applyBatchExpiry();
// The applied TTL is reflected locally instead of one refresh request per key.
expect(rowTtlBadge("alpha")?.textContent).toContain("redis.ttlHour");
expect(rowTtlBadge("alpha")?.textContent).not.toContain("redis.noExpiry");
expect(mocks.redisScanKeysBatch).toHaveBeenCalledTimes(1);
// PERSIST flips the same badge back to the no-expiry label.
requiredElement<HTMLButtonElement>("[data-redis-select-all]").click();
await settle();
requiredElement<HTMLButtonElement>("[data-redis-batch-expiry]").click();
await settle();
await applyBatchExpiry();
expect(mocks.redisSetKeysTtl).toHaveBeenLastCalledWith("connection", 0, ["YWxwaGE="], -1);
expect(rowTtlBadge("alpha")?.textContent).toContain("redis.noExpiry");
expect(mocks.redisScanKeysBatch).toHaveBeenCalledTimes(1);
});
it("hides the action while nothing is selected", async () => {
mocks.redisScanKeysBatch.mockResolvedValue({ cursor: 0, keys: batchKeys, total_keys: batchKeys.length });
mountBrowser();
await settle();
expect(batchExpiryButton()).toBeNull();
expect(document.querySelector("[data-redis-batch-expiry-apply]")).toBeNull();
});
});
describe("RedisKeyBrowser fuzzy key hierarchy", () => {
it("deletes a leaf directly from the key list after confirmation", async () => {
const key = { key_display: "session:current", key_raw: "c2Vzc2lvbjpjdXJyZW50", key_type: "string", ttl: -1 };
@@ -26,6 +26,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -54,6 +56,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -17,6 +17,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -44,6 +46,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -17,6 +17,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -44,6 +46,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -17,6 +17,8 @@ const mocks = vi.hoisted(() => ({
redisStreamAdd: vi.fn(),
redisSetTtl: vi.fn(),
redisSetExpireAt: vi.fn(),
redisSetKeysTtl: vi.fn(),
redisSetKeysExpireAt: vi.fn(),
redisCheckJsonModule: vi.fn(),
redisDeleteKey: vi.fn(),
redisDeleteKeys: vi.fn(),
@@ -44,6 +46,8 @@ vi.mock("@/lib/backend/api", () => ({
redisStreamAdd: mocks.redisStreamAdd,
redisSetTtl: mocks.redisSetTtl,
redisSetExpireAt: mocks.redisSetExpireAt,
redisSetKeysTtl: mocks.redisSetKeysTtl,
redisSetKeysExpireAt: mocks.redisSetKeysExpireAt,
redisCheckJsonModule: mocks.redisCheckJsonModule,
redisDeleteKey: mocks.redisDeleteKey,
redisDeleteKeys: mocks.redisDeleteKeys,
@@ -65,7 +65,7 @@ import { REDIS_SCAN_PAGE_SIZE_DEFAULT } from "@/lib/redis/redisKeyPattern";
import { chunkRedisKeyRaws, collectUniqueRedisKeys } from "@/lib/redis/redisKeyBatch";
import { getRedisCreateKeyTypeHelp, redisCreateKeyTypeHelpOptionOnOpen, shouldActivateRedisCreateKeyTypeHelpOnFocus } from "@/lib/redis/redisCreateKeyTypeHelp";
import { optionHelpPanelOffsetTop } from "@/lib/common/optionHelpPanelOffset";
import { applyRedisExpiryPolicy, type RedisExpiryMode, validateRedisExpiry } from "@/lib/redis/redisExpiry";
import { applyRedisBatchExpiryPolicy, applyRedisExpiryPolicy, type RedisExpiryMode, type RedisExpiryPolicy, validateRedisExpiry } from "@/lib/redis/redisExpiry";
import { shouldLoadMoreRedisKeys } from "@/lib/redis/redisKeyInfiniteScroll";
import { formatTtl } from "@/lib/common/ttlFormat";
import { computeTtlCountdownValue } from "@/lib/redis/redisAutoRefresh";
@@ -136,6 +136,11 @@ const redisExpiryTransport = {
setExpireAt: api.redisSetExpireAt,
};
const redisBatchExpiryTransport = {
setKeysTtl: api.redisSetKeysTtl,
setKeysExpireAt: api.redisSetKeysExpireAt,
};
const flatKeys = shallowRef<RedisKeyInfo[]>([]);
const treeKeys = shallowRef<RedisKeyTreeNode[]>([]);
let flatKeyByRaw = new Map<string, RedisKeyInfo>();
@@ -178,6 +183,13 @@ const noExpiryProjectionEpoch = ref(0);
const selectionAnchorRowId = ref<string | null>(null);
const selectedGroupLeafCounts = shallowRef<Map<string, number>>(new Map());
const deletingKeys = ref(false);
const showBatchExpiryDialog = ref(false);
const savingBatchExpiry = ref(false);
const batchExpiryMode = ref<RedisExpiryMode>("none");
const batchExpiryTtl = ref("");
const batchExpiryExpireAt = shallowRef<CalendarDateTime | null>(null);
/** Snapshot taken when the dialog opens so a background refresh cannot retarget the batch. */
const batchExpiryKeyRaws = shallowRef<string[]>([]);
const pendingDanger = ref<{ kind: "delete-keys"; title: string; keyRaws: string[]; loadedSearchResults: boolean } | { kind: "command"; command: string } | null>(null);
const showDangerConfirm = ref(false);
const commandText = ref("");
@@ -293,7 +305,9 @@ const isFuzzyKeySearch = computed(() => searchMode.value === "key" && isSearchMo
const fuzzyTreeLimitReached = computed(() => isFuzzyKeySearch.value && !canBuildRedisFuzzyTree(flatKeys.value.length));
const useFlatKeySearchRows = computed(() => showCustomGrouping.value || (searchMode.value === "key" && isSearchMode.value && !fuzzyKeySearch.value) || fuzzyTreeLimitReached.value);
const isFuzzyHierarchyView = computed(() => isFuzzyKeySearch.value && !fuzzyTreeLimitReached.value);
const selectionBusy = computed(() => deletingKeys.value || loading.value || loadingMore.value || isFetchingAll.value || searchPending.value);
/** True while a key-list mutation (delete or batch expiry) owns the visible result set. */
const mutatingKeys = computed(() => deletingKeys.value || savingBatchExpiry.value);
const selectionBusy = computed(() => mutatingKeys.value || loading.value || loadingMore.value || isFetchingAll.value || searchPending.value);
// checkedKeys is always a subset of loaded keys, so size equality is enough.
const allLoadedKeysSelected = computed(() => flatKeys.value.length > 0 && checkedKeys.value.size === flatKeys.value.length);
const allKeysSelected = computed(() => (customGrouping.value.enabled ? filteredFlatKeys.value.length > 0 && checkedKeys.value.size === filteredFlatKeys.value.length : allLoadedKeysSelected.value && !hasMore.value));
@@ -1142,7 +1156,7 @@ function onRedisKeyScroll(event: Event) {
const shouldLoad = shouldLoadMoreRedisKeys({
enabled: redisInfiniteScrollEnabled.value,
hasMore: hasMore.value,
busy: loading.value || loadingMore.value || searchPending.value || deletingKeys.value || isFetchingAll.value,
busy: loading.value || loadingMore.value || searchPending.value || mutatingKeys.value || isFetchingAll.value,
loadedKeys: flatKeys.value.length,
maxKeys: redisInfiniteScrollMaxKeys.value,
scrollTop: scroller.scrollTop,
@@ -1789,6 +1803,116 @@ function scrollCommandTerminalToEnd() {
});
}
// ---------------------------------------------------------------------------
// Batch expiration
// ---------------------------------------------------------------------------
/** Keeps only the given loaded keys checked, so a partial batch failure can be retried. */
function retainCheckedKeys(keyRaws: Iterable<string>) {
const keep = new Set(keyRaws);
const nextChecked = new Set<string>();
for (const keyRaw of checkedKeys.value) {
if (keep.has(keyRaw) && loadedKeyRaws.has(keyRaw)) nextChecked.add(keyRaw);
}
checkedKeys.value = nextChecked;
selectedGroupLeafCounts.value = groupLeafCountsFromChecked(nextChecked);
selectionEpoch.value++;
}
/**
* Writes a server-confirmed TTL straight into one loaded row, and reports
* whether its no-expiry membership changed.
*
* The batch result already carries the applied TTL, so the list badge and its
* countdown update without one refresh request per key.
*/
function applyKeyTtlMetadata(keyRaw: string, ttl: number): boolean {
const keyInfo = flatKeyByRaw.get(keyRaw);
if (!keyInfo) return false;
const previousTtl = keyInfo.ttl ?? -2;
const nextKeyInfo: RedisKeyInfo = { ...keyInfo, ttl };
if (!updateRedisKeyInfoMetadataByRaw(flatKeyByRaw, nextKeyInfo)) return false;
recordKeyTtlObservedAt(nextKeyInfo);
if (treeIndex) updateRedisKeyTreeLeafMetadata(treeIndex, nextKeyInfo);
return (previousTtl === -1) !== (ttl === -1);
}
function applyBatchExpiryMetadata(keyRaws: readonly string[], policy: RedisExpiryPolicy) {
const nowSeconds = Math.ceil(Date.now() / 1_000);
let noExpiryMembershipChanged = false;
for (const keyRaw of keyRaws) {
if (policy.mode === "at") {
const remaining = policy.expireAt - nowSeconds;
// EXPIREAT with an already-past timestamp deletes the key instead of expiring it.
if (remaining <= 0) {
onKeyDeleted(keyRaw);
continue;
}
if (applyKeyTtlMetadata(keyRaw, remaining)) noExpiryMembershipChanged = true;
continue;
}
if (applyKeyTtlMetadata(keyRaw, policy.mode === "ttl" ? policy.ttl : -1)) noExpiryMembershipChanged = true;
}
// Publish one metadata refresh for the whole batch: a 1000-key selection must
// not schedule 1000 reactive updates or 1000 countdown-timer re-checks.
if (noExpiryMembershipChanged) noExpiryProjectionEpoch.value++;
keyMetadataEpoch.value++;
syncListTtlTimer();
}
function openBatchExpiryDialog() {
if (checkedKeys.value.size === 0 || selectionBusy.value) return;
batchExpiryKeyRaws.value = [...checkedKeys.value];
batchExpiryMode.value = "none";
batchExpiryTtl.value = "";
batchExpiryExpireAt.value = null;
showBatchExpiryDialog.value = true;
}
function onBatchExpiryDialogOpenChange(open: boolean) {
if (!open && savingBatchExpiry.value) return;
showBatchExpiryDialog.value = open;
}
async function saveBatchExpiry() {
if (savingBatchExpiry.value || batchExpiryKeyRaws.value.length === 0) return;
const validation = validateRedisExpiry(batchExpiryMode.value, batchExpiryTtl.value, batchExpiryExpireAt.value);
if (!validation.valid) {
toast(expiryValidationMessage(validation.reason), 3000);
return;
}
const keyRaws = batchExpiryKeyRaws.value;
savingBatchExpiry.value = true;
try {
const summary = await applyRedisBatchExpiryPolicy(redisBatchExpiryTransport, props.connectionId, props.db, keyRaws, validation.policy);
const failed = new Set(summary.failedKeyRaws);
applyBatchExpiryMetadata(
keyRaws.filter((keyRaw) => !failed.has(keyRaw)),
validation.policy,
);
if (failed.size > 0) {
// Keep only the keys that were not updated so the user can retry them directly.
retainCheckedKeys(failed);
toast(t("redis.batchExpiryPartial", { success: summary.applied, failed: failed.size }), 5000);
} else {
resetCheckedKeys();
toast(t("redis.batchExpirySuccess", { count: summary.applied }), 3000);
}
// Surface the underlying cause as well; the count toast above keeps the partial result.
if (summary.errors.length > 0) toast(summary.errors[0], 5000);
} catch (error) {
toast(errorMessage(error), 5000);
} finally {
savingBatchExpiry.value = false;
showBatchExpiryDialog.value = false;
batchExpiryKeyRaws.value = [];
}
}
function appendCommandHistory(entry: Omit<RedisCommandHistoryEntry, "id">): number {
const id = ++commandHistoryId;
commandHistory.value = [...commandHistory.value, { id, ...entry }];
@@ -3044,8 +3168,9 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });
>{{ customGrouping.enabled ? t("redisGrouping.selectLoaded") : t("redis.selectAllLoaded") }}</Button
>
<Button v-if="checkedKeys.size > 0" variant="ghost" size="sm" class="h-6 shrink-0 px-1.5 text-xs" :disabled="selectionBusy" data-redis-deselect-all @click="clearAllCheckedKeys">{{ t("redis.deselectAll") }}</Button>
<Button v-if="checkedKeys.size > 0" variant="ghost" size="sm" class="h-6 shrink-0 px-1.5 text-xs" :disabled="selectionBusy" :title="t('redis.batchExpiry')" data-redis-batch-expiry @click="openBatchExpiryDialog"><Clock class="w-3 h-3 mr-1" />{{ t("redis.batchExpiry") }}</Button>
<Button v-if="checkedKeys.size > 0" variant="ghost" size="sm" class="h-6 shrink-0 text-xs text-destructive" :disabled="selectionBusy" data-redis-batch-delete @click="requestBatchDelete"><Trash2 class="w-3 h-3 mr-1" />{{ checkedKeys.size }}</Button>
<Button variant="ghost" size="icon" class="h-6 w-6 shrink-0" :disabled="deletingKeys || loading || loadingMore || isFetchingAll" @click="loadKeys">
<Button variant="ghost" size="icon" class="h-6 w-6 shrink-0" :disabled="mutatingKeys || loading || loadingMore || isFetchingAll" @click="loadKeys">
<Loader2 v-if="loading" class="h-3 w-3 animate-spin" />
<RefreshCw v-else class="h-3 w-3" />
</Button>
@@ -3204,7 +3329,7 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });
<div v-else-if="flatKeys.length === 0 && !loading" class="flex-1 flex flex-col items-center justify-center text-muted-foreground text-xs p-4 text-center">
<template v-if="hasMore">
<span class="mb-3">{{ t("redis.noKeysInScanHint") }}</span>
<Button variant="outline" size="sm" class="h-7 text-xs" :disabled="loadingMore || searchPending || deletingKeys" @click="loadMore()">
<Button variant="outline" size="sm" class="h-7 text-xs" :disabled="loadingMore || searchPending || mutatingKeys" @click="loadMore()">
<Loader2 v-if="loadingMore" class="w-3 h-3 mr-1.5 animate-spin" />
{{ t("redis.loadMoreKeys") }}
</Button>
@@ -3303,11 +3428,11 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });
{{ 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 || deletingKeys" @click="loadMore()">
<Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loadingMore || loading || searchPending || mutatingKeys" @click="loadMore()">
<Loader2 v-if="loadingMore" class="w-3 h-3 mr-1.5 animate-spin" />
{{ t("redis.loadMoreKeys") }}
</Button>
<Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loading || searchPending || deletingKeys || !hasMore" @click="fetchAll">
<Button variant="outline" size="sm" class="h-7 text-xs flex-1" :disabled="loading || searchPending || mutatingKeys || !hasMore" @click="fetchAll">
{{ t("redis.fetchAllKeys") }}
</Button>
</div>
@@ -3315,7 +3440,7 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });
<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 || deletingKeys" @click="stopFetchAll">
<Button variant="destructive" size="sm" class="h-7 text-xs w-full" :disabled="fetchAllStopRequested || mutatingKeys" @click="stopFetchAll">
{{ t("redis.stopFetchAll") }}
</Button>
</div>
@@ -3454,6 +3579,49 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });
<DangerConfirmDialog v-model:open="showDangerConfirm" :message="dangerMessage" :details="dangerDetails" :confirm-label="dangerConfirmLabel" :loading="deletingKeys" :close-on-confirm="pendingDanger?.kind !== 'delete-keys'" @confirm="applyDangerAction" />
<Dialog :open="showBatchExpiryDialog" @update:open="onBatchExpiryDialogOpenChange">
<DialogContent class="sm:max-w-[420px]">
<DialogHeader>
<DialogTitle>{{ t("redis.batchExpiryTitle") }}</DialogTitle>
</DialogHeader>
<div class="grid gap-3">
<p v-if="batchExpiryKeyRaws.length > 0" class="text-xs text-muted-foreground">{{ t("redis.batchExpirySelected", { count: batchExpiryKeyRaws.length }) }}</p>
<div class="grid gap-1.5 text-xs font-medium">
<span>{{ t("redis.expiry") }}</span>
<Select v-model="batchExpiryMode" :disabled="savingBatchExpiry">
<SelectTrigger class="h-8 text-xs" data-redis-batch-expiry-mode>
<SelectValue />
</SelectTrigger>
<SelectContent data-redis-expiry-mode-content>
<SelectItem value="none">{{ t("redis.expiryNone") }}</SelectItem>
<SelectItem value="ttl">{{ t("redis.expiryTtl") }}</SelectItem>
<SelectItem value="at">{{ t("redis.expiryAt") }}</SelectItem>
</SelectContent>
</Select>
<label v-if="batchExpiryMode === 'ttl'" class="grid gap-1.5 text-xs font-medium">
<span>{{ t("redis.createKeyTtl") }}</span>
<Input v-model="batchExpiryTtl" data-redis-batch-expiry-ttl class="dbx-editor-font-family h-8 text-xs" :disabled="savingBatchExpiry" inputmode="numeric" :placeholder="t('redis.createKeyTtlPlaceholder')" @keydown.enter="saveBatchExpiry" />
</label>
<label v-else-if="batchExpiryMode === 'at'" class="grid gap-1.5 text-xs font-medium">
<span>{{ t("redis.expiryAt") }}</span>
<DateTimePicker v-model="batchExpiryExpireAt" full-width :locale="locale" :disabled="savingBatchExpiry" />
</label>
</div>
</div>
<DialogFooter>
<Button variant="ghost" :disabled="savingBatchExpiry" @click="showBatchExpiryDialog = false">
{{ t("dangerDialog.cancel") }}
</Button>
<Button :disabled="savingBatchExpiry || batchExpiryKeyRaws.length === 0" data-redis-batch-expiry-apply @click="saveBatchExpiry">
<Loader2 v-if="savingBatchExpiry" class="h-4 w-4 animate-spin" />
{{ t("redis.batchExpiryApply") }}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<Dialog :open="showCreateKeyDialog" @update:open="onCreateKeyDialogOpenChange">
<DialogContent class="sm:max-w-md" :show-close-button="!creatingKey" :style="editorFontFamilyStyle">
<DialogHeader>