feat(redis): download large Redis values

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-30 18:57:37 +08:00
1 parent 0292d4c984
commit 43b6e218b0
19 files changed
+166 -4

No files matched your search

@@ -5,7 +5,7 @@ import type { CalendarDateTime } from "@internationalized/date";
import { useI18n } from "vue-i18n";
import { onClickOutside } from "@vueuse/core";
import { DynamicScroller, DynamicScrollerItem, RecycleScroller } from "vue-virtual-scroller";
import { Check, ChevronDown, Copy, ClipboardCopy, Eye, Trash2, Save, RefreshCw, Plus, Loader2, Pencil, WrapText, ArrowUp, ArrowDown, ArrowUpDown, Search, X, FileArchive } from "@lucide/vue";
import { Check, ChevronDown, Copy, ClipboardCopy, Eye, Trash2, Save, RefreshCw, Plus, Loader2, Pencil, WrapText, ArrowUp, ArrowDown, ArrowUpDown, Search, X, FileArchive, Download } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
@@ -69,6 +69,7 @@ import { unixSecondsToCalendarDateTime } from "@/components/ui/date-time-picker/
import { applyRedisExpiryPolicy, type RedisExpiryMode, redisExpiryModeForTtl, validateRedisExpiry } from "@/lib/redis/redisExpiry";
import { redisKeyRawToText, redisKeyTextToDisplay, redisKeyTextToRaw } from "@/lib/redis/redisCommandSession";
import { formatBytes } from "@/lib/database/serverMetrics";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
const { t, locale } = useI18n();
const { toast } = useToast();
@@ -103,6 +104,7 @@ const REDIS_COLLECTION_ROW_HEIGHT = 32;
const REDIS_STREAM_MIN_ROW_HEIGHT = 96;
const data = ref<RedisValue | null>(null);
const loading = ref(false);
const downloadingLargeValue = ref(false);
const loadingMore = ref(false);
const showRenameKeyDialog = ref(false);
const renamingKey = ref(false);
@@ -674,6 +676,46 @@ const largeStringPreviewHint = computed(() => {
}
return t("redis.largeStringPreviewHintUnknown", { loaded: formatBytes(loaded) });
});
function redisDownloadFileName(keyDisplay: string, encoding: RedisBlob["encoding"]): string {
const safe =
keyDisplay
.replace(/[\\/:*?"<>|\u0000-\u001f]/g, "_")
.trim()
.slice(0, 120) || "redis-value";
return `${safe}.${encoding === "utf8" ? "txt" : "bin"}`;
}
async function downloadLargeValue() {
if (downloadingLargeValue.value || !isStringValueTruncated.value) return;
downloadingLargeValue.value = true;
try {
const blob = await api.redisGetRawValue(props.connectionId, props.db, props.keyRaw);
const bytes = decodeRedisBlob(blob);
const filename = redisDownloadFileName(props.keyDisplay, blob.encoding);
if (isTauriRuntime()) {
const [{ save }, { writeFile }] = await Promise.all([import("@tauri-apps/plugin-dialog"), import("@tauri-apps/plugin-fs")]);
const extension = blob.encoding === "utf8" ? "txt" : "bin";
const path = await save({ defaultPath: filename, filters: [{ name: t(blob.encoding === "utf8" ? "redis.downloadValueTextFileType" : "redis.downloadValueFileType"), extensions: [extension] }] });
if (path) {
await writeFile(path, bytes);
toast(t("redis.downloadValueSuccess"), 2500);
}
} else {
const url = URL.createObjectURL(new Blob([bytes.slice().buffer as ArrayBuffer], { type: blob.encoding === "utf8" ? "text/plain;charset=utf-8" : "application/octet-stream" }));
const anchor = document.createElement("a");
anchor.href = url;
anchor.download = filename;
anchor.click();
URL.revokeObjectURL(url);
toast(t("redis.downloadValueSuccess"), 2500);
}
} catch (error) {
toast(errorMessage(error), 4000);
} finally {
downloadingLargeValue.value = false;
}
}
const streamRows = computed<RedisStreamRow[]>(() => {
if (redisKind.value !== "stream") return [];
return streamEntries.value.map((entry, index) => ({
@@ -2953,7 +2995,12 @@ useUpdateBlocker(() => (hasUnsavedRedisDraft.value || editingTtl.value || saving
<pre v-else class="dbx-editor-font-family min-h-0 w-full min-w-0 max-w-full flex-1 overflow-auto bg-background p-4 text-sm leading-6" :class="detailTextClass(stringValueView)">{{ detailTextForFormat(stringValueDetail, stringValueView) }}</pre>
<div v-if="isStringValueTruncated" data-redis-large-string-preview class="flex shrink-0 items-center gap-2 border-t bg-muted/30 px-4 py-2 text-xs text-muted-foreground">
<Eye class="h-3.5 w-3.5 shrink-0" />
<span>{{ largeStringPreviewHint }}</span>
<span class="min-w-0 flex-1">{{ largeStringPreviewHint }}</span>
<Button variant="outline" size="sm" class="h-7 shrink-0" :disabled="downloadingLargeValue" :title="t('redis.downloadValue')" :aria-label="t('redis.downloadValue')" @click="downloadLargeValue">
<Loader2 v-if="downloadingLargeValue" class="mr-1 h-3 w-3 animate-spin" />
<Download v-else class="mr-1 h-3 w-3" />
{{ t("redis.downloadValue") }}
</Button>
</div>
<div v-else-if="isBinaryStringValue" class="px-4 py-2 border-t text-xs text-muted-foreground shrink-0">
{{ t("redis.binaryStringReadonlyHint") }}
+4
View File
@@ -6171,6 +6171,10 @@ export default {
unsupportedValueTypeHint: "This is a proprietary type of kvrocks-compatible servers; DBX has not adapted it yet",
largeStringPreviewHint: "This value is large. Only the first {loaded} of {total} is loaded, and the preview is read-only.",
largeStringPreviewHintUnknown: "This value is large. Only the first {loaded} is loaded, and the preview is read-only.",
downloadValue: "Download full value",
downloadValueFileType: "Redis value",
downloadValueTextFileType: "Text file",
downloadValueSuccess: "Redis value downloaded",
largeStringPreviewActionUnavailable: "Large-value previews cannot be copied, decoded, or used to generate insert statements",
selectedKeys: "Selected keys",
selectAllLoaded: "Select all",
+4
View File
@@ -5776,6 +5776,10 @@ export default withEnglishFallback({
keySearchHistory: "Historial de búsqueda",
keySearchHistoryForget: "Eliminar del historial",
keySearchHistoryEmpty: "No hay historial",
downloadValue: "Descargar valor completo",
downloadValueFileType: "Valor de Redis",
downloadValueTextFileType: "Archivo de texto",
downloadValueSuccess: "Valor de Redis descargado",
},
mongo: {
documents: "{count} documentos",
+4
View File
@@ -5698,6 +5698,10 @@ export default withEnglishFallback({
keySearchHistory: "Cronologia ricerche",
keySearchHistoryForget: "Rimuovi dalla cronologia",
keySearchHistoryEmpty: "Nessuna cronologia",
downloadValue: "Scarica valore completo",
downloadValueFileType: "Valore Redis",
downloadValueTextFileType: "File di testo",
downloadValueSuccess: "Valore Redis scaricato",
},
mongo: {
documents: "{count} documenti",
+4
View File
@@ -5726,6 +5726,10 @@ export default withEnglishFallback({
keySearchHistory: "検索履歴",
keySearchHistoryForget: "履歴から削除",
keySearchHistoryEmpty: "履歴はありません",
downloadValue: "完全な値をダウンロード",
downloadValueFileType: "Redis 値",
downloadValueTextFileType: "テキストファイル",
downloadValueSuccess: "Redis 値をダウンロードしました",
},
mongo: {
documents: "{count}ドキュメント",
+4
View File
@@ -5361,6 +5361,10 @@ export default withEnglishFallback({
keySearchHistory: "검색 기록",
keySearchHistoryForget: "기록에서 제거",
keySearchHistoryEmpty: "검색 기록이 없습니다",
downloadValue: "전체 값 다운로드",
downloadValueFileType: "Redis 값",
downloadValueTextFileType: "텍스트 파일",
downloadValueSuccess: "Redis 값이 다운로드됨",
},
mongo: {
documents: "문서 {count}개",
+4
View File
@@ -5700,6 +5700,10 @@ export default withEnglishFallback({
keySearchHistory: "Histórico de pesquisa",
keySearchHistoryForget: "Remover do histórico",
keySearchHistoryEmpty: "Nenhum histórico",
downloadValue: "Baixar valor completo",
downloadValueFileType: "Valor Redis",
downloadValueTextFileType: "Arquivo de texto",
downloadValueSuccess: "Valor Redis baixado",
},
mongo: {
documents: "{count} documentos",
+4
View File
@@ -6726,6 +6726,10 @@ export default withEnglishFallback({
keyspace: "Пространство ключей",
},
},
downloadValue: "Скачать полное значение",
downloadValueFileType: "Значение Redis",
downloadValueTextFileType: "Текстовый файл",
downloadValueSuccess: "Значение Redis скачано",
},
mongoDump: {
selectAll: "Выбрать все коллекции",
+4
View File
@@ -6144,6 +6144,10 @@ export default withEnglishFallback({
unsupportedValueTypeHint: "这是 kvrocks 等兼容服务的专有类型,DBX 尚未适配",
largeStringPreviewHint: "值过大,仅加载前 {loaded}(共 {total})。预览为只读。",
largeStringPreviewHintUnknown: "值过大,仅加载前 {loaded}。预览为只读。",
downloadValue: "下载完整值",
downloadValueFileType: "Redis 值",
downloadValueTextFileType: "文本文件",
downloadValueSuccess: "Redis 值已下载",
largeStringPreviewActionUnavailable: "大值预览不支持复制、解码或生成插入语句",
selectedKeys: "已选择的 key",
selectAllLoaded: "全选",
+4
View File
@@ -4829,6 +4829,10 @@ export default withEnglishFallback({
unsupportedValueTypeHint: "這是 kvrocks 等相容服務的專有類型,DBX 尚未支援",
largeStringPreviewHint: "值過大,僅載入前 {loaded}(共 {total})。預覽為唯讀。",
largeStringPreviewHintUnknown: "值過大,僅載入前 {loaded}。預覽為唯讀。",
downloadValue: "下載完整值",
downloadValueFileType: "Redis 值",
downloadValueTextFileType: "文字檔",
downloadValueSuccess: "Redis 值已下載",
largeStringPreviewActionUnavailable: "大值預覽不支援複製、解碼或產生插入語句",
selectedKeys: "已選擇的 key",
selectAllLoaded: "全選",
+1
View File
@@ -583,6 +583,7 @@ export const redisScanKeys = forward("redisScanKeys");
export const redisScanKeysBatch = forward("redisScanKeysBatch");
export const redisScanValues = forward("redisScanValues");
export const redisGetValue = forward("redisGetValue");
export const redisGetRawValue = forward("redisGetRawValue");
export const redisGetTtl = forward("redisGetTtl");
export const redisGetStreamEntries = forward("redisGetStreamEntries");
export const redisGetStreamGroups = forward("redisGetStreamGroups");
+5
View File
@@ -110,6 +110,7 @@ import type {
DownloadedUpdate,
UpdateDownloadSource,
RedisCollectionPage,
RedisBlob,
RedisDatabaseInfo,
RedisStreamConsumer,
RedisStreamGroup,
@@ -3556,6 +3557,10 @@ export async function redisGetValue(connectionId: string, db: number, keyRaw: st
return post("/api/redis/get-value", { connectionId, db, keyRaw });
}
export async function redisGetRawValue(connectionId: string, db: number, keyRaw: string): Promise<RedisBlob> {
return post("/api/redis/get-raw-value", { connectionId, db, keyRaw });
}
export async function redisGetTtl(connectionId: string, db: number, keyRaw: string): Promise<number> {
return post("/api/redis/get-ttl", { connectionId, db, keyRaw });
}
+4
View File
@@ -3412,6 +3412,10 @@ export async function redisGetValue(connectionId: string, db: number, keyRaw: st
return invoke("redis_get_value", { connectionId, db, keyRaw });
}
export async function redisGetRawValue(connectionId: string, db: number, keyRaw: string): Promise<RedisBlob> {
return invoke("redis_get_raw_value", { connectionId, db, keyRaw });
}
export async function redisGetTtl(connectionId: string, db: number, keyRaw: string): Promise<number> {
return invoke("redis_get_ttl", { connectionId, db, keyRaw });
}