25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(redis): support multiple value formats in viewer (#2766)
onenewcodeba81fa4497f8
diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.vue b/apps/desktop/src/components/redis/RedisKeyBrowser.vueindex 472b66ccc6..9d258955af 100644--- a/apps/desktop/src/components/redis/RedisKeyBrowser.vue+++ b/apps/desktop/src/components/redis/RedisKeyBrowser.vue@@ -26,7 +26,7 @@ import { buildRedisKeyTree, collectExpandedGroupIds, collectRedisGroupKeyRaws, fimport { classifyRedisCommandSafety } from "@/lib/redis/redisCommandSafety";import { isRedisMutatingCommand } from "@/lib/redis/redisCommandTable";import { isRedisClearScreenCommand, nextRedisCommandDb, redisKeyTextToRaw } from "@/lib/redis/redisCommandSession";-import { formatRedisConsoleValue, formatRedisStringValue } from "@/lib/redis/redisValuePresentation";+import { formatRedisConsoleValue, redisValuePreview, redisValueSize } from "@/lib/redis/redisValuePresentation";import { isCancelSearchShortcut } from "@/lib/editor/keyboardShortcuts";import { copyToClipboard } from "@/lib/common/clipboard";import { useEditorFontFamilyStyle } from "@/composables/useEditorFontFamilyStyle";@@ -388,10 +388,10 @@ function redisValueToKeyInfo(value: RedisValue): RedisKeyInfo {return {key_display: value.key_display,key_raw: value.key_raw,- key_type: value.key_type,+ key_type: value.redis_type,ttl: value.ttl,- size: typeof value.value === "string" ? value.value.length : (value.total ?? 0),- value_preview: createdKeyPreview(value.value),+ size: redisValueSize(value),+ value_preview: redisValuePreview(value),};}@@ -642,23 +642,14 @@ function openCreateKeyDialog() {showCreateKeyDialog.value = true;}-function createdKeyPreview(value: any): string {- if (typeof value === "string") {- const text = formatRedisStringValue(value).replace(/\s+/g, " ").trim();- return text.length > 160 ? `${text.slice(0, 160)}…` : text;- }- if (Array.isArray(value) && value.length > 0) return String(value.length);- return "";-}--function upsertCreatedKey(value: any) {+function upsertCreatedKey(value: RedisValue) {const keyInfo: RedisKeyInfo = {key_display: value.key_display,key_raw: value.key_raw,- key_type: value.key_type,+ key_type: value.redis_type,ttl: value.ttl,- size: typeof value.value === "string" ? value.value.length : (value.total ?? 0),- value_preview: createdKeyPreview(value.value),+ size: redisValueSize(value),+ value_preview: redisValuePreview(value),};const existingIndex = flatKeys.value.findIndex((key) => key.key_raw === keyInfo.key_raw);if (existingIndex >= 0) {diff --git a/apps/desktop/src/components/redis/RedisValueViewer.vue b/apps/desktop/src/components/redis/RedisValueViewer.vueindex 9edc598948..c829676463 100644--- a/apps/desktop/src/components/redis/RedisValueViewer.vue+++ b/apps/desktop/src/components/redis/RedisValueViewer.vue@@ -3,7 +3,7 @@ import { computed, ref, nextTick, onBeforeUnmount, onMounted } from "vue";import { useI18n } from "vue-i18n";import { onClickOutside } from "@vueuse/core";import { DynamicScroller, DynamicScrollerItem, RecycleScroller } from "vue-virtual-scroller";-import { Braces, Copy, Eye, FileText, Terminal, Trash2, Save, RefreshCw, Plus, Loader2, Pencil, WrapText, IndentIncrease, IndentDecrease, ArrowUp, ArrowDown, ArrowUpDown, Search } from "@lucide/vue";+import { Copy, Eye, Terminal, Trash2, Save, RefreshCw, Plus, Loader2, Pencil, WrapText, IndentIncrease, IndentDecrease, ArrowUp, ArrowDown, ArrowUpDown, Search } from "@lucide/vue";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Badge } from "@/components/ui/badge";@@ -12,15 +12,33 @@ import { Sheet, SheetContent, SheetFooter, SheetHeader, SheetTitle } from "@/comimport DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";import RedisJsonTree from "./RedisJsonTree.vue";import * as api from "@/lib/backend/api";-import type { RedisKeyInfo, RedisValue } from "@/lib/backend/api";+import type { RedisBlob, RedisHashItem, RedisKeyInfo, RedisListItem, RedisSetItem, RedisStreamEntry, RedisValue, RedisZsetItem } from "@/lib/backend/api";import { useToast } from "@/composables/useToast";import { useTheme } from "@/composables/useTheme";import { useEditorFontFamilyStyle } from "@/composables/useEditorFontFamilyStyle";import { createRedisShikiJsonHighlighter, type RedisJsonHighlighter } from "@/lib/redis/redisJsonHighlighter";import { copyToClipboard } from "@/lib/common/clipboard";import { formatTtl } from "@/lib/common/ttlFormat";+import {+ canRenderRedisValueFormat,+ canEditRedisMemberDetail,+ clampRedisMemberDetailSheetWidth,+ formatRedisMemberDetail,+ getRedisMemberSelectionKey,+ isRedisBlob,+ preferredRedisValueFormat,+ REDIS_VALUE_FORMAT_DISPLAY_ORDER,+ redisBlobText,+ redisCollectionPageItems,+ redisMemberCopyText,+ redisValueCopyText,+ redisValueCollectionItems,+ redisValueCollectionScanCursor,+ redisValueCollectionTotal,+ type RedisCollectionItem,+ type RedisValueFormat,+} from "@/lib/redis/redisValuePresentation";import { safeJsonFormat } from "@/lib/common/safeJsonFormat";-import { canEditRedisMemberDetail, clampRedisMemberDetailSheetWidth, formatRedisMemberDetail, getRedisMemberSelectionKey } from "@/lib/redis/redisValuePresentation";const { t } = useI18n();const { toast } = useToast();@@ -37,6 +55,11 @@ const props = defineProps<{const emit = defineEmits<{ deleted: []; loaded: [value: RedisValue] }>();+const REDIS_JSON_WRAP_STORAGE_KEY = "dbx-redis-json-word-wrap";+const REDIS_VALUE_FORMAT_STORAGE_KEY = "dbx-redis-value-format";+const REDIS_COLLECTION_ROW_HEIGHT = 32;+const REDIS_STREAM_MIN_ROW_HEIGHT = 96;+const data = ref<RedisValue | null>(null);const loading = ref(false);const loadingMore = ref(false);@@ -54,7 +77,7 @@ const editTtlWrapper = ref<HTMLElement>();onClickOutside(editTtlWrapper, () => {if (editingTtl.value) cancelEditTtl();});-const collectionItems = ref<any[]>([]);+const collectionItems = ref<RedisCollectionItem[]>([]);const scanCursor = ref<number | undefined>(undefined);const selectedMemberTitle = ref("");const selectedMemberRaw = ref<unknown>("");@@ -71,10 +94,9 @@ const isResizingHashColumns = ref(false);const zsetTableRef = ref<HTMLElement | null>(null);const zsetScoreWidth = ref(220);const isResizingZsetColumns = ref(false);-type RedisValueView = "json" | "raw";-const REDIS_JSON_WRAP_STORAGE_KEY = "dbx-redis-json-word-wrap";-const stringValueView = ref<RedisValueView>("raw");-const memberValueView = ref<RedisValueView>("raw");+const stringValueView = ref<RedisValueFormat>(readPreferredRedisValueFormat());+const memberValueView = ref<RedisValueFormat>(readPreferredRedisValueFormat());+const redisJsonView = ref<"raw" | "tree">("raw");const redisJsonWordWrap = ref(readRedisJsonWordWrap());const redisJsonHighlighter = ref<RedisJsonHighlighter>();const hashSortBy = ref<"field" | "value" | null>(null);@@ -94,29 +116,133 @@ function toggleHashSort(column: "field" | "value") {}}-const sortedHashItems = computed<any[]>(() => {- if (!hashSortBy.value) return collectionItems.value;- const items = [...collectionItems.value];+const redisKind = computed(() => data.value?.data.kind ?? "unknown");+const isStringLikeKind = computed(() => redisKind.value === "string");+const stringBlob = computed<RedisBlob | null>(() => {+ const value = data.value;+ if (!value) return null;+ return value.data.kind === "string" ? value.data.content : null;+});+const stringValueDetail = computed(() => (stringBlob.value ? formatRedisMemberDetail(stringBlob.value, { allowJsonText: true }) : null));+const redisJsonValue = computed(() => (data.value?.data.kind === "json" ? data.value.data.value : null));+const selectedMemberDetail = computed(() => formatRedisMemberDetail(selectedMemberRaw.value, { allowJsonText: true }));+const redisJsonAppearance = computed(() => (isDark.value ? "dark" : "light"));+const isBinaryStringValue = computed(() => Boolean(stringValueDetail.value?.binary));+const selectedMemberCanEdit = computed(() => selectedMemberContext.value?.canEdit ?? false);+const canEditCurrentStringFormat = computed(() => Boolean(stringValueDetail.value?.editable) && stringValueView.value === "utf8");+const canEditCurrentMemberFormat = computed(() => selectedMemberCanEdit.value && memberValueView.value === "utf8");+const hasMore = computed(() => scanCursor.value != null && scanCursor.value > 0);+const collectionTotal = computed(() => (data.value ? redisValueCollectionTotal(data.value) : null));+const hashGridStyle = computed(() => ({+ gridTemplateColumns: `${hashFieldWidth.value}px minmax(12rem, 1fr) 84px`,+}));+const zsetGridStyle = computed(() => ({+ gridTemplateColumns: `${zsetScoreWidth.value}px minmax(0, 1fr) 84px`,+}));+const metadataSizeLabel = computed(() => {+ const metadata = props.metadata;+ const size = metadata?.size ?? 0;+ if (!metadata || size <= 0) return "";+ if (metadata.key_type === "string") {+ if (size >= 1024) return `${(size / 1024).toFixed(1)} KB`;+ return `${size} B`;+ }+ return String(size);+});+const streamRows = computed<RedisStreamRow[]>(() => {+ if (data.value?.data.kind !== "stream") return [];+ return data.value.data.entries.map((entry, index) => ({+ id: `${index}:${entry.id}`,+ index,+ entry,+ }));+});++const sortedHashItems = computed<RedisHashItem[]>(() => {+ if (redisKind.value !== "hash") return [];+ const items = [...(collectionItems.value as RedisHashItem[])];+ if (!hashSortBy.value) return items;const multiplier = hashSortDir.value === "asc" ? 1 : -1;const key = hashSortBy.value;items.sort((a, b) => {- const av = String(a[key] ?? "");- const bv = String(b[key] ?? "");+ const av = key === "field" ? formatRedisMemberDetail(a.field).rawText : formatRedisMemberDetail(a.value).rawText;+ const bv = key === "field" ? formatRedisMemberDetail(b.field).rawText : formatRedisMemberDetail(b.value).rawText;return av.localeCompare(bv) * multiplier;});return items;});-const hashCollectionRows = computed<RedisCollectionRow[]>(() =>+const hashCollectionRows = computed<RedisCollectionRow<RedisHashItem>[]>(() =>sortedHashItems.value.map((value, index) => ({- id: `hash-sorted-${index}`,+ id: `hash-${index}`,index,value,})),);+const listRows = computed<RedisCollectionRow<RedisListItem>[]>(() =>+ redisKind.value === "list"+ ? (collectionItems.value as RedisListItem[]).map((value, index) => ({+ id: collectionRowId(value, index),+ index,+ value,+ }))+ : [],+);+const setRows = computed<RedisCollectionRow<RedisSetItem>[]>(() =>+ redisKind.value === "set"+ ? (collectionItems.value as RedisSetItem[]).map((value, index) => ({+ id: collectionRowId(value, index),+ index,+ value,+ }))+ : [],+);+const zsetRows = computed<RedisCollectionRow<RedisZsetItem>[]>(() =>+ redisKind.value === "zset"+ ? (collectionItems.value as RedisZsetItem[]).map((value, index) => ({+ id: collectionRowId(value, index),+ index,+ value,+ }))+ : [],+);+let hashSearchTimer: ReturnType<typeof setTimeout> | null = null;let hashSearchRequestId = 0;+let memberSheetResizeStartX = 0;+let memberSheetResizeStartWidth = 0;+let hashResizeStartX = 0;+let hashResizeStartWidth = 0;+let zsetResizeStartX = 0;+let zsetResizeStartWidth = 0;++type PendingDelete = { kind: "key" } | { kind: "hash"; field: string } | { kind: "list"; index: number } | { kind: "set"; member: string } | { kind: "zset"; member: string };+const pendingDelete = ref<PendingDelete | null>(null);++type RedisMemberContext =+ | { kind: "list"; index: number; canEdit: boolean }+ | { kind: "set"; member: string | null; canEdit: boolean }+ | { kind: "hash"; field: string | null; canEdit: boolean }+ | { kind: "zset"; member: string | null; score: string; canEdit: boolean }+ | { kind: "stream"; field: string; canEdit: false };++type RedisCollectionRow<T> = {+ id: string;+ index: number;+ value: T;+};++type RedisStreamRow = {+ id: string;+ index: number;+ entry: RedisStreamEntry;+};++function collectionCountLabel(kind: "items" | "fields" | "members", loaded: number, total?: number | null) {+ if (total == null || total === loaded) return t(`redis.${kind}`, { count: loaded });+ return t(`redis.loaded${kind[0].toUpperCase()}${kind.slice(1)}`, { loaded, total });+}function onHashSearchInput() {if (hashSearchTimer) clearTimeout(hashSearchTimer);@@ -140,15 +266,14 @@ function onHashSearchKeydown(event: KeyboardEvent) {async function onHashSearch() {const query = hashSearchQuery.value.trim();- if (!data.value) return;+ if (redisKind.value !== "hash") return;const requestId = ++hashSearchRequestId;searchLoading.value = true;try {const result = await api.redisLoadMore(props.connectionId, props.db, props.keyRaw, "hash", 0, 200, query || undefined);- if (requestId !== hashSearchRequestId) return;- const items = Array.isArray(result.value) ? result.value : [];+ if (requestId !== hashSearchRequestId || result.kind !== "hash") return;activeHashSearchQuery.value = query;- collectionItems.value = items;+ collectionItems.value = result.items;scanCursor.value = result.scan_cursor ?? undefined;clearSelectedMember();} finally {@@ -156,75 +281,6 @@ async function onHashSearch() {}}-const selectedMemberDetail = computed(() => formatRedisMemberDetail(selectedMemberRaw.value));-const selectedMemberJsonDetail = computed(() => selectedMemberDetail.value.json ?? null);-const stringValueDetail = computed(() => (data.value?.key_type === "string" ? formatRedisMemberDetail(data.value.value) : null));-const stringJsonDetail = computed(() => stringValueDetail.value?.json ?? null);-const redisJsonAppearance = computed(() => (isDark.value ? "dark" : "light"));-const memberRawJsonHtml = computed(() => (selectedMemberJsonDetail.value ? highlightRedisJson(selectedMemberJsonDetail.value.rawText) : ""));-const hashGridStyle = computed(() => ({- gridTemplateColumns: `${hashFieldWidth.value}px minmax(12rem, 1fr) 84px`,-}));-const zsetGridStyle = computed(() => ({- gridTemplateColumns: `${zsetScoreWidth.value}px minmax(0, 1fr) 84px`,-}));-const selectedMemberCanEdit = computed(() => selectedMemberContext.value != null && canEditRedisMemberDetail(selectedMemberContext.value.kind));-const REDIS_COLLECTION_ROW_HEIGHT = 32;-const REDIS_STREAM_MIN_ROW_HEIGHT = 96;--type PendingDelete = { kind: "key" } | { kind: "hash"; field: string } | { kind: "list"; index: number } | { kind: "set"; member: string } | { kind: "zset"; member: string };--const pendingDelete = ref<PendingDelete | null>(null);--let memberSheetResizeStartX = 0;-let memberSheetResizeStartWidth = 0;-let hashResizeStartX = 0;-let hashResizeStartWidth = 0;-let zsetResizeStartX = 0;-let zsetResizeStartWidth = 0;--type RedisMemberContext = { kind: "list"; index: number } | { kind: "set"; member: string } | { kind: "hash"; field: string } | { kind: "zset"; member: string; score: number } | { kind: "stream"; field: string };--type RedisCollectionRow = {- id: string;- index: number;- value: any;-};--type RedisStreamRow = {- id: string;- index: number;- entry: {- id?: string | number;- fields?: Record<string, unknown>;- };-};--const collectionRows = computed<RedisCollectionRow[]>(() =>- collectionItems.value.map((value, index) => ({- id: `${index}`,- index,- value,- })),-);--const streamRows = computed<RedisStreamRow[]>(() => {- if (!data.value || data.value.key_type !== "stream" || !Array.isArray(data.value.value)) return [];- return data.value.value.map((entry, index) => ({- id: `${index}:${String(entry?.id ?? "")}`,- index,- entry,- }));-});--function streamFields(entry: RedisStreamRow["entry"]): [string, unknown][] {- return Object.entries(entry.fields ?? {});-}--function streamFieldCount(row: RedisStreamRow): number {- return streamFields(row.entry).length;-}-function readRedisJsonWordWrap(): boolean {try {return localStorage.getItem(REDIS_JSON_WRAP_STORAGE_KEY) !== "false";@@ -242,9 +298,77 @@ function setRedisJsonWordWrap(value: boolean) {}}-function rawRedisValueText(value: unknown): string {- if (typeof value === "string") return value;- return String(value ?? "");+function readPreferredRedisValueFormat(): RedisValueFormat {+ try {+ const stored = localStorage.getItem(REDIS_VALUE_FORMAT_STORAGE_KEY);+ if (stored === "raw") return "utf8";+ return stored === "utf8" || stored === "ascii" || stored === "binary" || stored === "json" || stored === "javaserialize" || stored === "hex" || stored === "base64" ? stored : "utf8";+ } catch {+ return "utf8";+ }+}++function formatJsonText(raw: string): string | null {+ try {+ return safeJsonFormat(raw, 2);+ } catch {+ return null;+ }+}++function compressJsonText(raw: string): string | null {+ try {+ return safeJsonFormat(raw);+ } catch {+ return null;+ }+}++function rememberRedisValueFormat(format: RedisValueFormat) {+ try {+ localStorage.setItem(REDIS_VALUE_FORMAT_STORAGE_KEY, format);+ } catch {+ // Ignore storage failures; the toggle still works for the current session.+ }+}++function setStringValueFormat(format: RedisValueFormat) {+ stringValueView.value = format;+ if (stringValueDetail.value && canRenderRedisValueFormat(stringValueDetail.value, format)) {+ rememberRedisValueFormat(format);+ }+}++function setMemberValueFormat(format: RedisValueFormat) {+ memberValueView.value = format;+ if (canRenderRedisValueFormat(selectedMemberDetail.value, format)) {+ rememberRedisValueFormat(format);+ }+}++function redisFormatLabel(format: RedisValueFormat, rawLabel?: string): string {+ switch (format) {+ case "utf8":+ return "UTF-8";+ case "ascii":+ return "ASCII";+ case "binary":+ return "Binary";+ case "json":+ return t("redis.jsonView");+ case "javaserialize":+ return "Java Serialized";+ case "hex":+ return t("grid.hexViewerHex");+ case "base64":+ return "Base64";+ default:+ return rawLabel || t("redis.rawContent");+ }+}++function isTextRedisFormat(format: RedisValueFormat): boolean {+ return format === "utf8" || format === "ascii" || format === "binary";}function highlightRedisJson(json: string): string {@@ -255,6 +379,36 @@ function escapeHtml(value: string): string {return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");}+function detailTextForFormat(detail: ReturnType<typeof formatRedisMemberDetail>, format: RedisValueFormat): string {+ switch (format) {+ case "utf8":+ return detail.utf8Text;+ case "ascii":+ return detail.asciiText;+ case "binary":+ return detail.binaryText;+ case "json":+ return detail.json?.formattedText ?? detail.rawText;+ case "javaserialize":+ return detail.javaSerialized?.formattedText ?? detail.rawText;+ case "hex":+ return detail.hexRows.map((row) => row.hex).join("\n");+ case "base64":+ return detail.base64Text;+ default:+ return detail.rawText;+ }+}++function detailTextClass(format: RedisValueFormat): string {+ if (!redisJsonWordWrap.value) return "whitespace-pre";+ return format === "ascii" || format === "binary" ? "whitespace-pre-wrap break-all" : "whitespace-pre-wrap break-words";+}++function rawRedisValueText(value: unknown): string {+ return formatRedisMemberDetail(value).rawText;+}+const deleteDetails = computed(() => {const pending = pendingDelete.value;if (!pending) return "";@@ -266,24 +420,6 @@ const deleteDetails = computed(() => {return t("dangerDialog.redisSetMemberDetails", { key, member: formatValue(pending.member) });});-const isBinaryStringValue = computed(() => data.value?.key_type === "string" && data.value?.value_is_binary);-const hasMore = computed(() => scanCursor.value != null && scanCursor.value > 0);-const metadataSizeLabel = computed(() => {- const metadata = props.metadata;- const size = metadata?.size ?? 0;- if (!metadata || size <= 0) return "";- if (metadata.key_type === "string") {- if (size >= 1024) return `${(size / 1024).toFixed(1)} KB`;- return `${size} B`;- }- return String(size);-});--function collectionCountLabel(kind: "items" | "fields" | "members", loaded: number, total?: number | null) {- if (total == null || total === loaded) return t(`redis.${kind}`, { count: loaded });- return t(`redis.loaded${kind[0].toUpperCase()}${kind.slice(1)}`, { loaded, total });-}-async function load(options: { selectDefaultMember?: boolean } = {}) {const shouldSelectDefaultMember = options.selectDefaultMember ?? true;if (hashSearchTimer) clearTimeout(hashSearchTimer);@@ -297,17 +433,23 @@ async function load(options: { selectDefaultMember?: boolean } = {}) {const loadedValue = await api.redisGetValue(props.connectionId, props.db, props.keyRaw);data.value = loadedValue;emit("loaded", loadedValue);- scanCursor.value = data.value.scan_cursor ?? undefined;- if (data.value.key_type === "string") {- const detail = formatRedisMemberDetail(data.value.value);+ scanCursor.value = redisValueCollectionScanCursor(loadedValue);+ collectionItems.value = redisValueCollectionItems(loadedValue);+ isEditing.value = false;++ if (loadedValue.data.kind === "string") {+ const detail = formatRedisMemberDetail(loadedValue.data.content, { allowJsonText: true });editValue.value = detail.rawText;- stringValueView.value = detail.format === "json" ? "json" : "raw";+ stringValueView.value = preferredRedisValueFormat(loadedValue.data.content, readPreferredRedisValueFormat(), { allowJsonText: true });+ clearSelectedMember();+ } else if (loadedValue.data.kind === "json") {+ editValue.value = JSON.stringify(loadedValue.data.value, null, 2);+ redisJsonView.value = "raw";clearSelectedMember();- } else if (["list", "set", "zset", "hash"].includes(data.value.key_type)) {- collectionItems.value = Array.isArray(data.value.value) ? [...data.value.value] : [];- if (shouldSelectDefaultMember) selectDefaultMember(data.value);- } else if (data.value.key_type === "stream") {- if (shouldSelectDefaultMember) selectDefaultMember(data.value);+ } else if (loadedValue.data.kind === "stream") {+ if (shouldSelectDefaultMember) selectDefaultMember(loadedValue);+ } else if (["list", "set", "hash", "zset"].includes(loadedValue.data.kind)) {+ if (shouldSelectDefaultMember) selectDefaultMember(loadedValue);} else {clearSelectedMember();}@@ -317,15 +459,16 @@ async function load(options: { selectDefaultMember?: boolean } = {}) {}async function loadMore() {- if (!data.value || !hasMore.value || loadingMore.value || (data.value.key_type === "hash" && searchLoading.value)) return;- const keyType = data.value.key_type;+ if (!data.value || !hasMore.value || loadingMore.value || (redisKind.value === "hash" && searchLoading.value)) return;+ if (!(redisKind.value === "list" || redisKind.value === "set" || redisKind.value === "hash" || redisKind.value === "zset")) return;+ const keyType = redisKind.value;const hashFilter = keyType === "hash" ? activeHashSearchQuery.value || undefined : undefined;const requestId = hashSearchRequestId;loadingMore.value = true;try {const result = await api.redisLoadMore(props.connectionId, props.db, props.keyRaw, keyType, scanCursor.value!, 200, hashFilter);if (keyType === "hash" && requestId !== hashSearchRequestId) return;- const newItems = Array.isArray(result.value) ? result.value : [];+ const newItems = redisCollectionPageItems(result);collectionItems.value = [...collectionItems.value, ...newItems];scanCursor.value = result.scan_cursor ?? undefined;} finally {@@ -334,35 +477,32 @@ async function loadMore() {}async function saveString() {- if (isBinaryStringValue.value) return;+ if (!data.value || !stringBlob.value || isBinaryStringValue.value) return;await api.redisSetString(props.connectionId, props.db, props.keyRaw, editValue.value);isEditing.value = false;await load();}function handleStringInput() {- if (!isBinaryStringValue.value) {+ if (canEditCurrentStringFormat.value) {isEditing.value = true;}}-function formatJsonText(raw: string): string | null {- try {- return safeJsonFormat(raw, 2);- } catch {- return null;- }+async function saveJson() {+ if (!data.value || data.value.data.kind !== "json") return;+ await api.redisJsonSet(props.connectionId, props.db, props.keyRaw, editValue.value);+ isEditing.value = false;+ await load();}-function compressJsonText(raw: string): string | null {- try {- return safeJsonFormat(raw);- } catch {- return null;+function handleJsonInput() {+ if (redisJsonView.value === "raw") {+ isEditing.value = true;}}-function handleFormatStringJson() {+function handleFormatJsonEditor() {const result = formatJsonText(editValue.value);if (result != null) {editValue.value = result;@@ -372,7 +512,7 @@ function handleFormatStringJson() {}}-function handleCompressStringJson() {+function handleCompressJsonEditor() {const result = compressJsonText(editValue.value);if (result != null) {editValue.value = result;@@ -382,26 +522,6 @@ function handleCompressStringJson() {}}-function handleFormatMemberJson() {- const result = formatJsonText(memberEditValue.value);- if (result != null) {- memberEditValue.value = result;- isEditingMember.value = true;- } else {- toast(t("redis.jsonFormatError"), 3000);- }-}--function handleCompressMemberJson() {- const result = compressJsonText(memberEditValue.value);- if (result != null) {- memberEditValue.value = result;- isEditingMember.value = true;- } else {- toast(t("redis.jsonFormatError"), 3000);- }-}-async function applyDeleteKey() {await api.redisDeleteKey(props.connectionId, props.db, props.keyRaw);emit("deleted");@@ -414,7 +534,7 @@ function requestDeleteKey() {async function copyValue() {if (!data.value) return;- const text = typeof data.value.value === "string" ? data.value.value : JSON.stringify(data.value.value, null, 2);+ const text = redisValueCopyText(data.value, collectionItems.value);try {await copyToClipboard(text);toast(t("redis.copied"), 2000);@@ -436,63 +556,71 @@ function escapeRedisArg(val: string): string {return `"${val.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;}+function blobWriteText(blob: RedisBlob): string | null {+ return redisBlobText(blob);+}+function generateInsertStatements(): string | null {if (!data.value) return null;- if (data.value.value_is_binary) return null;const key = data.value.key_display;- const type = data.value.key_type;const commands: string[] = [];-- const isCollection = ["list", "set", "zset", "hash"].includes(type);- if (isCollection) {- const total = data.value.total;- const loaded = collectionItems.value.length;- if (total != null && total > loaded) {- commands.push(`-- Note: Only ${loaded} of ${total} items included`);- }+ const total = collectionTotal.value;+ if (total != null && total > collectionItems.value.length) {+ commands.push(`-- Note: Only ${collectionItems.value.length} of ${total} items included`);}- switch (type) {- case "string":- commands.push(`SET ${escapeRedisArg(key)} ${escapeRedisArg(String(data.value.value))}`);+ switch (data.value.data.kind) {+ case "string": {+ const text = blobWriteText(data.value.data.content);+ if (text == null) return null;+ commands.push(`SET ${escapeRedisArg(key)} ${escapeRedisArg(text)}`);+ break;+ }+ case "json": {+ commands.push(`JSON.SET ${escapeRedisArg(key)} $ ${escapeRedisArg(JSON.stringify(data.value.data.value))}`);break;+ }case "list": {- const items = collectionItems.value.map((v) => escapeRedisArg(String(v))).join(" ");- commands.push(`RPUSH ${escapeRedisArg(key)} ${items}`);+ const items = (collectionItems.value as RedisListItem[]).map((item) => blobWriteText(item.value));+ if (items.some((item) => item == null)) return null;+ commands.push(`RPUSH ${escapeRedisArg(key)} ${(items as string[]).map(escapeRedisArg).join(" ")}`);break;}case "set": {- const members = collectionItems.value.map((v) => escapeRedisArg(String(v))).join(" ");- commands.push(`SADD ${escapeRedisArg(key)} ${members}`);+ const items = (collectionItems.value as RedisSetItem[]).map((item) => blobWriteText(item.member));+ if (items.some((item) => item == null)) return null;+ commands.push(`SADD ${escapeRedisArg(key)} ${(items as string[]).map(escapeRedisArg).join(" ")}`);break;}case "zset": {- const pairs = collectionItems.value.map((v) => `${v.score} ${escapeRedisArg(String(v.member))}`).join(" ");- commands.push(`ZADD ${escapeRedisArg(key)} ${pairs}`);+ const pairs = (collectionItems.value as RedisZsetItem[]).map((item) => {+ const member = blobWriteText(item.member);+ return member == null ? null : `${item.score} ${escapeRedisArg(member)}`;+ });+ if (pairs.some((item) => item == null)) return null;+ commands.push(`ZADD ${escapeRedisArg(key)} ${(pairs as string[]).join(" ")}`);break;}case "hash": {- const pairs = collectionItems.value.map((v) => `${escapeRedisArg(String(v.field))} ${escapeRedisArg(String(v.value))}`).join(" ");- commands.push(`HSET ${escapeRedisArg(key)} ${pairs}`);+ const pairs = (collectionItems.value as RedisHashItem[]).map((item) => {+ const field = blobWriteText(item.field);+ const value = blobWriteText(item.value);+ return field == null || value == null ? null : `${escapeRedisArg(field)} ${escapeRedisArg(value)}`;+ });+ if (pairs.some((item) => item == null)) return null;+ commands.push(`HSET ${escapeRedisArg(key)} ${(pairs as string[]).join(" ")}`);break;}case "stream": {- const entries = Array.isArray(data.value.value) ? data.value.value : [];- for (const entry of entries) {- const fields = Object.entries((entry as any).fields ?? {})- .map(([f, v]) => `${escapeRedisArg(f)} ${escapeRedisArg(String(v))}`)- .join(" ");+ for (const entry of data.value.data.entries) {+ const fields = entry.fields.map(({ field, value }) => `${escapeRedisArg(field)} ${escapeRedisArg(value)}`).join(" ");commands.push(`XADD ${escapeRedisArg(key)} * ${fields}`);}break;}default:- if (type === "ReJSON-RL" || type === "JSON") {- const json = JSON.stringify(data.value.value);- commands.push(`JSON.SET ${escapeRedisArg(key)} $ '${json}'`);- }- break;+ return null;}if (data.value.ttl > 0) {@@ -503,13 +631,11 @@ function generateInsertStatements(): string | null {}async function copyInsertStatement() {- if (!data.value) return;- if (data.value.value_is_binary) {+ const stmt = generateInsertStatements();+ if (!stmt) {toast(t("redis.copyInsertStatementBinary"), 3000);return;}- const stmt = generateInsertStatements();- if (!stmt) return;try {await copyToClipboard(stmt);toast(t("redis.copyInsertStatement"), 2000);@@ -519,18 +645,18 @@ async function copyInsertStatement() {}function copyMember(value: unknown) {- void copyText(formatRedisMemberDetail(value).rawText);+ void copyText(redisMemberCopyText(value));}-function selectMember(title: string, value: unknown, context: RedisMemberContext) {- const detail = formatRedisMemberDetail(value);+function selectMember(title: string, value: unknown, context: RedisMemberContext, identity?: string) {+ const detail = formatRedisMemberDetail(value, { allowJsonText: true });selectedMemberTitle.value = title;selectedMemberRaw.value = value;- selectedMemberKey.value = getRedisMemberSelectionKey(title, value);+ selectedMemberKey.value = getRedisMemberSelectionKey(title, value, identity);selectedMemberContext.value = context;isEditingMember.value = false;memberEditValue.value = detail.rawText;- memberValueView.value = detail.format === "json" ? "json" : "raw";+ memberValueView.value = preferredRedisValueFormat(value, readPreferredRedisValueFormat(), { allowJsonText: true });}function clearSelectedMember() {@@ -542,12 +668,12 @@ function clearSelectedMember() {memberEditValue.value = "";}-function isSelectedMember(title: string, value: unknown) {- return selectedMemberKey.value === getRedisMemberSelectionKey(title, value);+function isSelectedMember(title: string, value: unknown, identity?: string) {+ return selectedMemberKey.value === getRedisMemberSelectionKey(title, value, identity);}-function viewMember(title: string, value: unknown, context: RedisMemberContext) {- selectMember(title, value, context);+function viewMember(title: string, value: unknown, context: RedisMemberContext, identity?: string) {+ selectMember(title, value, context, identity);showMemberDetail.value = true;}@@ -635,6 +761,7 @@ function startResizeZsetColumns(event: PointerEvent) {}function startEditMember() {+ if (!canEditCurrentMemberFormat.value) return;memberEditValue.value = selectedMemberDetail.value.rawText;isEditingMember.value = true;}@@ -646,79 +773,174 @@ function cancelEditMember() {async function saveMemberEdit() {const context = selectedMemberContext.value;- if (!context || !selectedMemberCanEdit.value) return;- const title = selectedMemberTitle.value;+ if (!context || !canEditCurrentMemberFormat.value) return;let nextContext: RedisMemberContext = context;savingMember.value = true;try {if (context.kind === "list") {await api.redisListSet(props.connectionId, props.db, props.keyRaw, context.index, memberEditValue.value);} else if (context.kind === "hash") {+ if (!context.field) return;await api.redisHashSet(props.connectionId, props.db, props.keyRaw, context.field, memberEditValue.value);} else if (context.kind === "set") {+ if (!context.member) return;await api.redisSetRemove(props.connectionId, props.db, props.keyRaw, context.member);await api.redisSetAdd(props.connectionId, props.db, props.keyRaw, memberEditValue.value);- nextContext = { kind: "set", member: memberEditValue.value };+ nextContext = { kind: "set", member: memberEditValue.value, canEdit: true };} else if (context.kind === "zset") {+ if (!context.member) return;await api.redisZrem(props.connectionId, props.db, props.keyRaw, context.member);- await api.redisZadd(props.connectionId, props.db, props.keyRaw, memberEditValue.value, context.score);- nextContext = { kind: "zset", member: memberEditValue.value, score: context.score };+ await api.redisZadd(props.connectionId, props.db, props.keyRaw, memberEditValue.value, Number(context.score));+ nextContext = { kind: "zset", member: memberEditValue.value, score: context.score, canEdit: true };}const editedValue = memberEditValue.value;isEditingMember.value = false;await load({ selectDefaultMember: false });- selectMember(title, editedValue, nextContext);+ restoreSelectedMember(nextContext, editedValue);} finally {savingMember.value = false;}}function selectDefaultMember(redisValue: RedisValue) {- if (redisValue.key_type === "list" || redisValue.key_type === "set") {- if (collectionItems.value.length === 0) {- clearSelectedMember();- return;+ switch (redisValue.data.kind) {+ case "list": {+ const first = redisValue.data.items[0];+ if (!first) return clearSelectedMember();+ return selectMember(`#${first.index}`, first.value, { kind: "list", index: first.index, canEdit: canEditRedisMemberDetail("list", first.value) });}- selectMember(redisValue.key_type === "list" ? "#0" : t("redis.member"), collectionItems.value[0], redisValue.key_type === "list" ? { kind: "list", index: 0 } : { kind: "set", member: String(collectionItems.value[0]) });- return;- }-- if (redisValue.key_type === "hash") {- const first = collectionItems.value[0];- if (!first) {- clearSelectedMember();- return;+ case "set": {+ const first = redisValue.data.items[0];+ if (!first) return clearSelectedMember();+ const member = redisBlobText(first.member);+ return selectMember(t("redis.member"), first.member, { kind: "set", member, canEdit: member != null && canEditRedisMemberDetail("set", first.member) });}- selectMember(String(first.field), first.value, { kind: "hash", field: String(first.field) });- return;+ case "hash": {+ const first = redisValue.data.items[0];+ if (!first) return clearSelectedMember();+ const field = redisBlobText(first.field);+ return selectMember(formatValue(first.field), first.value, { kind: "hash", field, canEdit: field != null && canEditRedisMemberDetail("hash", first.value) });+ }+ case "zset": {+ const first = redisValue.data.items[0];+ if (!first) return clearSelectedMember();+ const member = redisBlobText(first.member);+ return selectMember(first.score, first.member, { kind: "zset", member, score: first.score, canEdit: member != null && canEditRedisMemberDetail("zset", first.member) });+ }+ case "stream": {+ const firstEntry = redisValue.data.entries[0];+ const firstField = firstEntry?.fields[0];+ if (!firstField) return clearSelectedMember();+ return selectMember(firstField.field, firstField.value, { kind: "stream", field: firstField.field, canEdit: false }, streamFieldSelectionIdentity(firstEntry.id, 0));+ }+ default:+ clearSelectedMember();}+}- if (redisValue.key_type === "zset") {- const first = collectionItems.value[0];- if (!first) {- clearSelectedMember();- return;- }- selectMember(String(first.score), first.member, {- kind: "zset",- member: String(first.member),- score: Number(first.score),- });+function streamFieldCount(row: RedisStreamRow): number {+ return row.entry.fields.length;+}++function streamFieldSelectionIdentity(entryId: string, fieldIndex: string | number): string {+ return `stream:${entryId}:${fieldIndex}`;+}++function collectionRowId(value: RedisCollectionItem, index: number): string {+ if ("index" in value) return `list-${value.index}`;+ if ("field" in value) return `hash-${value.field.raw_base64}-${index}`;+ if ("score" in value) return `zset-${value.member.raw_base64}-${index}`;+ return `set-${value.member.raw_base64}-${index}`;+}++function canDeleteHashItem(item: RedisHashItem): boolean {+ return redisBlobText(item.field) != null;+}++function canDeleteSetItem(item: RedisSetItem): boolean {+ return redisBlobText(item.member) != null;+}++function canDeleteZsetItem(item: RedisZsetItem): boolean {+ return redisBlobText(item.member) != null;+}++function restoreSelectedMember(context: RedisMemberContext, fallbackValue: string) {+ const restored = resolveSelectedMember(context);+ if (restored) {+ selectMember(restored.title, restored.value, restored.context);return;}+ const title = context.kind === "list" ? `#${context.index}` : context.kind === "set" ? t("redis.member") : context.kind === "hash" ? (context.field ?? selectedMemberTitle.value) : context.kind === "zset" ? context.score : context.field;+ selectMember(title, fallbackValue, context);+}- if (redisValue.key_type === "stream" && Array.isArray(redisValue.value)) {- const firstEntry = redisValue.value[0];- const firstField = firstEntry?.fields ? Object.entries(firstEntry.fields)[0] : undefined;- if (!firstField) {- clearSelectedMember();- return;+function resolveSelectedMember(context: RedisMemberContext): { title: string; value: unknown; context: RedisMemberContext } | null {+ switch (context.kind) {+ case "list": {+ if (redisKind.value !== "list") return null;+ const item = (collectionItems.value as RedisListItem[]).find((candidate) => candidate.index === context.index);+ if (!item) return null;+ return {+ title: `#${item.index}`,+ value: item.value,+ context: { kind: "list", index: item.index, canEdit: canEditRedisMemberDetail("list", item.value) },+ };}- selectMember(String(firstField[0]), firstField[1], { kind: "stream", field: String(firstField[0]) });- return;+ case "set": {+ if (redisKind.value !== "set" || !context.member) return null;+ const item = (collectionItems.value as RedisSetItem[]).find((candidate) => redisBlobText(candidate.member) === context.member);+ if (!item) return null;+ const member = redisBlobText(item.member);+ return {+ title: t("redis.member"),+ value: item.member,+ context: { kind: "set", member, canEdit: member != null && canEditRedisMemberDetail("set", item.member) },+ };+ }+ case "hash": {+ if (redisKind.value !== "hash" || !context.field) return null;+ const item = (collectionItems.value as RedisHashItem[]).find((candidate) => redisBlobText(candidate.field) === context.field);+ if (!item) return null;+ const field = redisBlobText(item.field);+ return {+ title: formatValue(item.field),+ value: item.value,+ context: { kind: "hash", field, canEdit: field != null && canEditRedisMemberDetail("hash", item.value) },+ };+ }+ case "zset": {+ if (redisKind.value !== "zset" || !context.member) return null;+ const item = (collectionItems.value as RedisZsetItem[]).find((candidate) => redisBlobText(candidate.member) === context.member && candidate.score === context.score);+ if (!item) return null;+ const member = redisBlobText(item.member);+ return {+ title: item.score,+ value: item.member,+ context: { kind: "zset", member, score: item.score, canEdit: member != null && canEditRedisMemberDetail("zset", item.member) },+ };+ }+ case "stream":+ return null;}+}- clearSelectedMember();+function requestHashDel(field: string | null) {+ if (!field) return;+ pendingDelete.value = { kind: "hash", field };+ showDeleteConfirm.value = true;+}++function requestSetRemove(member: string | null) {+ if (!member) return;+ pendingDelete.value = { kind: "set", member };+ showDeleteConfirm.value = true;+}++function requestZsetRemove(member: string | null) {+ if (!member) return;+ pendingDelete.value = { kind: "zset", member };+ showDeleteConfirm.value = true;}// TTL@@ -760,10 +982,6 @@ async function applyHashDel(field: string) {await api.redisHashDel(props.connectionId, props.db, props.keyRaw, field);await load();}-function requestHashDel(field: string) {- pendingDelete.value = { kind: "hash", field };- showDeleteConfirm.value = true;-}// Listasync function listPush() {@@ -798,10 +1016,6 @@ async function applySetRemove(member: string) {await api.redisSetRemove(props.connectionId, props.db, props.keyRaw, member);await load();}-function requestSetRemove(member: string) {- pendingDelete.value = { kind: "set", member };- showDeleteConfirm.value = true;-}// ZSetasync function zsetAdd() {@@ -819,10 +1033,6 @@ async function applyZsetRemove(member: string) {await api.redisZrem(props.connectionId, props.db, props.keyRaw, member);await load();}-function requestZsetRemove(member: string) {- pendingDelete.value = { kind: "zset", member };- showDeleteConfirm.value = true;-}async function confirmDelete() {const pending = pendingDelete.value;@@ -835,7 +1045,8 @@ async function confirmDelete() {pendingDelete.value = null;}-function formatValue(val: any): string {+function formatValue(val: unknown): string {+ if (isRedisBlob(val)) return formatRedisMemberDetail(val).text;if (typeof val === "string") return formatRedisMemberDetail(val).text;return JSON.stringify(val, null, 2);}@@ -878,7 +1089,7 @@ onBeforeUnmount(() => {</div><div class="flex min-h-7 flex-wrap items-center gap-2 px-4 pb-1">- <Badge variant="secondary" class="dbx-editor-font-family text-xs uppercase">{{ data.key_type }}</Badge>+ <Badge variant="secondary" class="dbx-editor-font-family text-xs uppercase">{{ data.redis_type }}</Badge><Badge v-if="metadataSizeLabel" variant="outline" class="text-xs text-muted-foreground"> {{ t("redis.columnSize") }}: {{ metadataSizeLabel }} </Badge><template v-if="!editingTtl"><Badge v-if="data.ttl > 0" variant="outline" class="text-xs cursor-pointer text-muted-foreground hover:bg-accent" @click="startEditTtl">TTL: {{ formatTtl(data.ttl, t) }}</Badge>@@ -892,56 +1103,121 @@ onBeforeUnmount(() => {</div><!-- String -->- <div v-if="data.key_type === 'string'" class="flex-1 flex flex-col overflow-hidden">- <div v-if="stringJsonDetail" class="flex h-9 items-center gap-2 border-b px-4 text-xs shrink-0">- <div class="flex overflow-hidden rounded-md border bg-muted/20 p-0.5">- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': stringValueView === 'json' }" @click="stringValueView = 'json'">- <Braces class="h-3.5 w-3.5" />- {{ t("redis.jsonView") }}+ <div v-if="isStringLikeKind && stringValueDetail" class="flex-1 flex flex-col overflow-hidden">+ <div class="flex h-9 items-center gap-2 border-b px-4 text-xs shrink-0">+ <div class="flex max-w-full overflow-x-auto rounded-md border bg-muted/20 p-0.5">+ <Button+ v-for="format in REDIS_VALUE_FORMAT_DISPLAY_ORDER"+ :key="format"+ variant="ghost"+ size="sm"+ class="h-6 shrink-0 rounded-[5px] px-2 text-xs"+ :class="{ 'bg-background shadow-sm': stringValueView === format }"+ :disabled="!canRenderRedisValueFormat(stringValueDetail, format)"+ @click="setStringValueFormat(format)"+ >+ {{ redisFormatLabel(format, stringValueDetail.rawLabel) }}</Button>- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': stringValueView === 'raw' }" @click="stringValueView = 'raw'">- <FileText class="h-3.5 w-3.5" />+ </div>+ <span class="flex-1" />+ <label v-if="isTextRedisFormat(stringValueView)" class="flex items-center gap-1.5 text-muted-foreground">+ <WrapText class="h-3.5 w-3.5" />+ {{ t("redis.wordWrap") }}+ <Switch size="sm" :model-value="redisJsonWordWrap" @update:model-value="setRedisJsonWordWrap(Boolean($event))" />+ </label>+ </div>+ <div v-if="isEditing" class="flex min-h-0 flex-1 flex-col">+ <textarea v-model="editValue" class="dbx-editor-font-family min-h-0 flex-1 resize-none bg-background p-4 text-sm outline-none" spellcheck="false" />+ </div>+ <div v-else-if="stringValueView === 'json' && stringValueDetail.json" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-4 text-sm leading-6">+ <RedisJsonTree :value="stringValueDetail.json.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />+ </div>+ <div v-else-if="stringValueView === 'javaserialize' && stringValueDetail.javaSerialized" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-4 text-sm leading-6">+ <RedisJsonTree :value="stringValueDetail.javaSerialized.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />+ </div>+ <div v-else-if="stringValueView === 'hex'" class="min-h-0 flex-1 overflow-auto bg-background p-4 text-xs leading-5">+ <div class="mb-3 flex items-center justify-between text-muted-foreground">+ <span>{{ t("grid.hexViewer") }}</span>+ <span>{{ t("grid.hexViewerByteCount", { count: stringValueDetail.byteCount }) }}</span>+ </div>+ <pre v-if="stringValueDetail.hexRows.length > 0" class="dbx-editor-font-family w-full min-w-0 max-w-full select-all whitespace-pre-wrap break-all">{{ detailTextForFormat(stringValueDetail, "hex") }}</pre>+ <div v-else class="text-muted-foreground">{{ t("grid.hexViewerEmpty") }}</div>+ </div>+ <pre v-else-if="stringValueView === 'base64'" 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 whitespace-pre-wrap break-all">{{ stringValueDetail.base64Text }}</pre>+ <textarea+ v-else-if="stringValueView === 'utf8' && canEditCurrentStringFormat"+ v-model="editValue"+ class="dbx-editor-font-family flex-1 resize-none bg-background p-4 text-sm outline-none"+ :class="redisJsonWordWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre'"+ :readonly="!canEditCurrentStringFormat"+ spellcheck="false"+ @input="handleStringInput"+ />+ <pre v-else-if="stringValueView === 'utf8'" 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>+ <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="isBinaryStringValue" class="px-4 py-2 border-t text-xs text-muted-foreground shrink-0">+ {{ t("redis.binaryStringReadonlyHint") }}+ </div>+ <div v-if="isEditing" class="px-4 py-2 border-t flex justify-end gap-2 shrink-0">+ <Button+ variant="ghost"+ size="sm"+ @click="+ isEditing = false;+ editValue = stringBlob ? rawRedisValueText(stringBlob) : '';+ "+ >{{ t("grid.discard") }}</Button+ >+ <Button size="sm" @click="saveString"><Save class="w-3 h-3 mr-1" /> {{ t("grid.save") }}</Button>+ </div>+ </div>++ <!-- Redis JSON -->+ <div v-else-if="redisKind === 'json' && redisJsonValue != null" class="flex-1 flex flex-col overflow-hidden">+ <div class="flex h-9 items-center gap-2 border-b px-4 text-xs shrink-0">+ <div class="flex overflow-hidden rounded-md border bg-muted/20 p-0.5">+ <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': redisJsonView === 'raw' }" @click="redisJsonView = 'raw'">{{ t("redis.rawContent") }}</Button>+ <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': redisJsonView === 'tree' }" @click="redisJsonView = 'tree'">+ {{ t("redis.jsonView") }}+ </Button></div><span class="flex-1" />- <Button v-if="stringValueView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.formatJson')" @click="handleFormatStringJson">+ <Button v-if="redisJsonView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.formatJson')" @click="handleFormatJsonEditor"><IndentIncrease class="h-3.5 w-3.5" /></Button>- <Button v-if="stringValueView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.compressJson')" @click="handleCompressStringJson">+ <Button v-if="redisJsonView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.compressJson')" @click="handleCompressJsonEditor"><IndentDecrease class="h-3.5 w-3.5" /></Button>- <label class="flex items-center gap-1.5 text-muted-foreground">+ <label v-if="redisJsonView === 'raw'" class="flex items-center gap-1.5 text-muted-foreground"><WrapText class="h-3.5 w-3.5" />{{ t("redis.wordWrap") }}<Switch size="sm" :model-value="redisJsonWordWrap" @update:model-value="setRedisJsonWordWrap(Boolean($event))" /></label></div>- <div v-if="stringJsonDetail && stringValueView === 'json'" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-4 text-sm leading-6">- <RedisJsonTree :value="stringJsonDetail.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />- </div>- <textarea v-else v-model="editValue" class="dbx-editor-font-family flex-1 p-4 text-sm bg-background resize-none outline-none" :class="{ 'whitespace-pre': stringJsonDetail && !redisJsonWordWrap }" :readonly="isBinaryStringValue" @input="handleStringInput" />- <div v-if="isBinaryStringValue" class="px-4 py-2 border-t text-xs text-muted-foreground shrink-0">- {{ t("redis.binaryStringReadonlyHint") }}+ <div v-if="redisJsonView === 'tree'" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-4 text-sm leading-6">+ <RedisJsonTree :value="redisJsonValue" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" /></div>+ <textarea v-else v-model="editValue" class="dbx-editor-font-family flex-1 resize-none bg-background p-4 text-sm outline-none" :class="redisJsonWordWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre'" spellcheck="false" @input="handleJsonInput" /><div v-if="isEditing" class="px-4 py-2 border-t flex justify-end gap-2 shrink-0"><Buttonvariant="ghost"size="sm"@click="isEditing = false;- editValue = rawRedisValueText(data.value);+ editValue = JSON.stringify(redisJsonValue, null, 2);">{{ t("grid.discard") }}</Button>- <Button size="sm" @click="saveString"><Save class="w-3 h-3 mr-1" /> {{ t("grid.save") }}</Button>+ <Button size="sm" @click="saveJson"><Save class="w-3 h-3 mr-1" /> {{ t("grid.save") }}</Button></div></div><!-- List -->- <div v-else-if="data.key_type === 'list'" class="flex-1 flex flex-col overflow-hidden">+ <div v-else-if="redisKind === 'list'" class="flex-1 flex flex-col overflow-hidden"><div class="flex items-center gap-2 px-4 py-1.5 border-b shrink-0">- <span class="text-xs text-muted-foreground">{{ collectionCountLabel("items", collectionItems.length, data.total) }}</span>+ <span class="text-xs text-muted-foreground">{{ collectionCountLabel("items", listRows.length, collectionTotal) }}</span><span class="flex-1" /><Input v-model="newValue" class="h-6 w-40 text-xs" placeholder="value" @keydown.enter="listPush" /><Button variant="ghost" size="sm" class="h-6 text-xs" @click="listPush"><Plus class="w-3 h-3 mr-1" />Push</Button>@@ -951,21 +1227,23 @@ onBeforeUnmount(() => {<div class="px-3 py-1 text-xs font-medium text-muted-foreground">Value</div><div /></div>- <RecycleScroller class="flex-1 overflow-y-auto" :items="collectionRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id">+ <RecycleScroller class="flex-1 overflow-y-auto" :items="listRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id"><template #default="{ item: row }"><divdata-redis-value-rowclass="dbx-editor-font-family grid grid-cols-[60px_1fr_84px] border-b text-sm hover:bg-accent/50 group cursor-pointer"- :class="{ 'bg-accent/60': isSelectedMember(`#${row.index}`, row.value) }"+ :class="{ 'bg-accent/60': isSelectedMember(`#${row.value.index}`, row.value.value) }":style="{ height: `${REDIS_COLLECTION_ROW_HEIGHT}px` }"- @click="viewMember(`#${row.index}`, row.value, { kind: 'list', index: row.index })"+ @click="viewMember(`#${row.value.index}`, row.value.value, { kind: 'list', index: row.value.index, canEdit: canEditRedisMemberDetail('list', row.value.value) })">- <div class="px-3 py-1.5 text-xs text-muted-foreground border-r">{{ row.index }}</div>- <div class="px-3 py-1.5 truncate">{{ formatValue(row.value) }}</div>+ <div class="px-3 py-1.5 text-xs text-muted-foreground border-r">{{ row.value.index }}</div>+ <div class="px-3 py-1.5 truncate">{{ formatValue(row.value.value) }}</div><div class="flex items-center justify-center gap-1">- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.viewMember')" @click.stop="viewMember(`#${row.index}`, row.value, { kind: 'list', index: row.index })"><Eye class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value)"><Copy class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" @click.stop="requestListRemove(row.index)"><Trash2 class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.viewMember')" @click.stop="viewMember(`#${row.value.index}`, row.value.value, { kind: 'list', index: row.value.index, canEdit: canEditRedisMemberDetail('list', row.value.value) })"+ ><Eye class="w-3 h-3"+ /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value.value)"><Copy class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" @click.stop="requestListRemove(row.value.index)"><Trash2 class="w-3 h-3" /></Button></div></div></template>@@ -981,9 +1259,9 @@ onBeforeUnmount(() => {</div><!-- Set -->- <div v-else-if="data.key_type === 'set'" class="flex-1 flex flex-col overflow-hidden">+ <div v-else-if="redisKind === 'set'" class="flex-1 flex flex-col overflow-hidden"><div class="flex items-center gap-2 px-4 py-1.5 border-b shrink-0">- <span class="text-xs text-muted-foreground">{{ collectionCountLabel("items", collectionItems.length, data.total) }}</span>+ <span class="text-xs text-muted-foreground">{{ collectionCountLabel("items", setRows.length, collectionTotal) }}</span><span class="flex-1" /><Input v-model="newValue" class="h-6 w-40 text-xs" placeholder="member" @keydown.enter="setAdd" /><Button variant="ghost" size="sm" class="h-6 text-xs" @click="setAdd"><Plus class="w-3 h-3 mr-1" />Add</Button>@@ -992,20 +1270,27 @@ onBeforeUnmount(() => {<div class="px-3 py-1 text-xs font-medium text-muted-foreground">Member</div><div /></div>- <RecycleScroller class="flex-1 overflow-y-auto" :items="collectionRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id">+ <RecycleScroller class="flex-1 overflow-y-auto" :items="setRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id"><template #default="{ item: row }"><divdata-redis-value-rowclass="dbx-editor-font-family grid grid-cols-[1fr_84px] border-b text-sm hover:bg-accent/50 group cursor-pointer"- :class="{ 'bg-accent/60': isSelectedMember(t('redis.member'), row.value) }"+ :class="{ 'bg-accent/60': isSelectedMember(t('redis.member'), row.value.member) }":style="{ height: `${REDIS_COLLECTION_ROW_HEIGHT}px` }"- @click="viewMember(t('redis.member'), row.value, { kind: 'set', member: String(row.value) })"+ @click="viewMember(t('redis.member'), row.value.member, { kind: 'set', member: redisBlobText(row.value.member), canEdit: redisBlobText(row.value.member) != null && canEditRedisMemberDetail('set', row.value.member) })">- <div class="px-3 py-1.5 truncate">{{ formatValue(row.value) }}</div>+ <div class="px-3 py-1.5 truncate">{{ formatValue(row.value.member) }}</div><div class="flex items-center justify-center gap-1">- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.viewMember')" @click.stop="viewMember(t('redis.member'), row.value, { kind: 'set', member: String(row.value) })"><Eye class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value)"><Copy class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" @click.stop="requestSetRemove(String(row.value))"><Trash2 class="w-3 h-3" /></Button>+ <Button+ variant="ghost"+ size="icon"+ class="h-5 w-5 opacity-0 group-hover:opacity-100"+ :title="t('redis.viewMember')"+ @click.stop="viewMember(t('redis.member'), row.value.member, { kind: 'set', member: redisBlobText(row.value.member), canEdit: redisBlobText(row.value.member) != null && canEditRedisMemberDetail('set', row.value.member) })"+ ><Eye class="w-3 h-3"+ /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value.member)"><Copy class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" :disabled="!canDeleteSetItem(row.value)" @click.stop="requestSetRemove(redisBlobText(row.value.member))"><Trash2 class="w-3 h-3" /></Button></div></div></template>@@ -1021,9 +1306,9 @@ onBeforeUnmount(() => {</div><!-- Hash -->- <div v-else-if="data.key_type === 'hash'" ref="hashTableRef" class="flex-1 flex flex-col overflow-hidden">+ <div v-else-if="redisKind === 'hash'" ref="hashTableRef" class="flex-1 flex flex-col overflow-hidden"><div class="flex items-center gap-2 px-4 py-1.5 border-b shrink-0">- <span class="text-xs text-muted-foreground shrink-0">{{ collectionCountLabel("fields", collectionItems.length, activeHashSearchQuery ? null : data.total) }}</span>+ <span class="text-xs text-muted-foreground shrink-0">{{ collectionCountLabel("fields", hashCollectionRows.length, activeHashSearchQuery ? null : collectionTotal) }}</span><div class="relative flex-1 max-w-60"><Search class="pointer-events-none absolute left-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground/80" /><Input v-model="hashSearchQuery" class="h-6 w-full pl-5 pr-2 text-xs" :placeholder="t('redis.searchFields')" @input="onHashSearchInput" @keydown="onHashSearchKeydown" />@@ -1060,8 +1345,8 @@ onBeforeUnmount(() => {data-redis-value-rowclass="dbx-editor-font-family grid border-b text-sm hover:bg-accent/50 group cursor-pointer":style="{ ...hashGridStyle, height: `${REDIS_COLLECTION_ROW_HEIGHT}px` }"- :class="{ 'bg-accent/60': isSelectedMember(String(row.value.field), row.value.value) }"- @click="viewMember(String(row.value.field), row.value.value, { kind: 'hash', field: String(row.value.field) })"+ :class="{ 'bg-accent/60': isSelectedMember(formatValue(row.value.field), row.value.value) }"+ @click="viewMember(formatValue(row.value.field), row.value.value, { kind: 'hash', field: redisBlobText(row.value.field), canEdit: redisBlobText(row.value.field) != null && canEditRedisMemberDetail('hash', row.value.value) })"><div class="px-3 py-1.5 text-blue-500 truncate border-r">{{ formatValue(row.value.field) }}</div><div class="px-3 py-1.5 truncate text-muted-foreground">{{ formatValue(row.value.value) }}</div>@@ -1071,16 +1356,11 @@ onBeforeUnmount(() => {size="icon"class="h-5 w-5 opacity-0 group-hover:opacity-100":title="t('redis.viewMember')"- @click.stop="- viewMember(String(row.value.field), row.value.value, {- kind: 'hash',- field: String(row.value.field),- })- "+ @click.stop="viewMember(formatValue(row.value.field), row.value.value, { kind: 'hash', field: redisBlobText(row.value.field), canEdit: redisBlobText(row.value.field) != null && canEditRedisMemberDetail('hash', row.value.value) })"><Eye class="w-3 h-3"/></Button><Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value.value)"><Copy class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" @click.stop="requestHashDel(String(row.value.field))"><Trash2 class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" :disabled="!canDeleteHashItem(row.value)" @click.stop="requestHashDel(redisBlobText(row.value.field))"><Trash2 class="w-3 h-3" /></Button></div></div></template>@@ -1096,9 +1376,9 @@ onBeforeUnmount(() => {</div><!-- Sorted Set -->- <div v-else-if="data.key_type === 'zset'" ref="zsetTableRef" class="flex-1 flex flex-col overflow-hidden">+ <div v-else-if="redisKind === 'zset'" ref="zsetTableRef" class="flex-1 flex flex-col overflow-hidden"><div class="flex items-center gap-2 px-4 py-1.5 border-b shrink-0">- <span class="text-xs text-muted-foreground">{{ collectionCountLabel("members", collectionItems.length, data.total) }}</span>+ <span class="text-xs text-muted-foreground">{{ collectionCountLabel("members", zsetRows.length, collectionTotal) }}</span><span class="flex-1" /><Input v-model="newScore" class="h-6 w-20 text-xs" placeholder="score" /><Input v-model="newValue" class="h-6 w-32 text-xs" placeholder="member" @keydown.enter="zsetAdd" />@@ -1112,20 +1392,14 @@ onBeforeUnmount(() => {<div class="px-3 py-1 text-xs font-medium text-muted-foreground min-w-0">Member</div><div /></div>- <RecycleScroller class="flex-1 overflow-y-auto" :items="collectionRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id">+ <RecycleScroller class="flex-1 overflow-y-auto" :items="zsetRows" :item-size="REDIS_COLLECTION_ROW_HEIGHT" :buffer="600" :skip-hover="true" key-field="id"><template #default="{ item: row }"><divdata-redis-value-rowclass="dbx-editor-font-family grid border-b text-sm hover:bg-accent/50 group cursor-pointer":class="{ 'bg-accent/60': isSelectedMember(String(row.value.score), row.value.member) }":style="{ ...zsetGridStyle, height: `${REDIS_COLLECTION_ROW_HEIGHT}px` }"- @click="- viewMember(String(row.value.score), row.value.member, {- kind: 'zset',- member: String(row.value.member),- score: Number(row.value.score),- })- "+ @click="viewMember(row.value.score, row.value.member, { kind: 'zset', member: redisBlobText(row.value.member), score: row.value.score, canEdit: redisBlobText(row.value.member) != null && canEditRedisMemberDetail('zset', row.value.member) })"><div class="px-3 py-1.5 text-muted-foreground text-xs border-r min-w-0 truncate" :title="String(row.value.score)">{{ row.value.score }}@@ -1139,17 +1413,11 @@ onBeforeUnmount(() => {size="icon"class="h-5 w-5 opacity-0 group-hover:opacity-100":title="t('redis.viewMember')"- @click.stop="- viewMember(String(row.value.score), row.value.member, {- kind: 'zset',- member: String(row.value.member),- score: Number(row.value.score),- })- "+ @click.stop="viewMember(row.value.score, row.value.member, { kind: 'zset', member: redisBlobText(row.value.member), score: row.value.score, canEdit: redisBlobText(row.value.member) != null && canEditRedisMemberDetail('zset', row.value.member) })"><Eye class="w-3 h-3"/></Button><Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(row.value.member)"><Copy class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" @click.stop="requestZsetRemove(String(row.value.member))"><Trash2 class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100 text-destructive" :disabled="!canDeleteZsetItem(row.value)" @click.stop="requestZsetRemove(redisBlobText(row.value.member))"><Trash2 class="w-3 h-3" /></Button></div></div></template>@@ -1165,7 +1433,7 @@ onBeforeUnmount(() => {</div><!-- Stream (readonly) -->- <div v-else-if="data.key_type === 'stream'" class="flex-1 flex flex-col overflow-hidden">+ <div v-else-if="redisKind === 'stream'" class="flex-1 flex flex-col overflow-hidden"><div class="px-4 py-1 text-xs text-muted-foreground border-b shrink-0">{{ t("redis.entries", { count: streamRows.length }) }}</div>@@ -1175,17 +1443,19 @@ onBeforeUnmount(() => {<div data-redis-stream-entry class="dbx-editor-font-family px-4 py-2 border-b text-sm hover:bg-accent/50"><div class="mb-1 text-xs text-muted-foreground">{{ row.entry.id }}</div><div- v-for="[field, val] in streamFields(row.entry)"- :key="field"+ v-for="(field, fieldIndex) in row.entry.fields"+ :key="`${row.id}:${field.field}:${fieldIndex}`"class="grid grid-cols-[minmax(6rem,0.35fr)_1fr_56px] gap-3 py-0.5 group cursor-pointer"- :class="{ 'bg-accent/60': isSelectedMember(String(field), val) }"- @click="viewMember(String(field), val, { kind: 'stream', field: String(field) })"+ :class="{ 'bg-accent/60': isSelectedMember(field.field, field.value, streamFieldSelectionIdentity(row.entry.id, fieldIndex)) }"+ @click="viewMember(field.field, field.value, { kind: 'stream', field: field.field, canEdit: false }, streamFieldSelectionIdentity(row.entry.id, fieldIndex))">- <span class="truncate text-blue-500">{{ field }}</span>- <span class="truncate text-muted-foreground">{{ val }}</span>+ <span class="truncate text-blue-500">{{ field.field }}</span>+ <span class="truncate text-muted-foreground">{{ field.value }}</span><span class="flex justify-end gap-1">- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.viewMember')" @click.stop="viewMember(String(field), val, { kind: 'stream', field: String(field) })"><Eye class="w-3 h-3" /></Button>- <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(val)"><Copy class="w-3 h-3" /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.viewMember')" @click.stop="viewMember(field.field, field.value, { kind: 'stream', field: field.field, canEdit: false }, streamFieldSelectionIdentity(row.entry.id, fieldIndex))"+ ><Eye class="w-3 h-3"+ /></Button>+ <Button variant="ghost" size="icon" class="h-5 w-5 opacity-0 group-hover:opacity-100" :title="t('redis.copyMember')" @click.stop="copyMember(field.value)"><Copy class="w-3 h-3" /></Button></span></div></div>@@ -1196,7 +1466,7 @@ onBeforeUnmount(() => {<!-- Unknown --><div v-else class="flex-1 overflow-auto p-4">- <pre class="dbx-editor-font-family text-sm whitespace-pre-wrap">{{ formatValue(data.value) }}</pre>+ <pre class="dbx-editor-font-family text-sm whitespace-pre-wrap">{{ formatValue(data.data) }}</pre></div></template>@@ -1216,52 +1486,52 @@ onBeforeUnmount(() => {<SheetHeader class="border-b px-5 py-4 pr-12"><SheetTitle class="flex items-center gap-2"><span class="truncate">{{ selectedMemberTitle ? formatValue(selectedMemberTitle) : t("redis.memberDetail") }}</span>- <Badge variant="outline" class="shrink-0 text-xs">{{ selectedMemberDetail.format.toUpperCase() }}</Badge>+ <Badge variant="outline" class="shrink-0 text-xs">{{ redisFormatLabel(memberValueView, selectedMemberDetail.rawLabel) }}</Badge></SheetTitle></SheetHeader><template v-if="isEditingMember">- <div v-if="selectedMemberJsonDetail" class="flex h-9 items-center gap-2 border-b px-5 text-xs shrink-0">- <span class="flex-1" />- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.formatJson')" @click="handleFormatMemberJson">- <IndentIncrease class="h-3.5 w-3.5" />- </Button>- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.compressJson')" @click="handleCompressMemberJson">- <IndentDecrease class="h-3.5 w-3.5" />- </Button>- </div><textarea v-model="memberEditValue" class="dbx-editor-font-family min-h-0 flex-1 resize-none bg-background p-5 text-[13px] leading-6 outline-none" spellcheck="false" /></template>- <template v-else-if="selectedMemberJsonDetail">+ <template v-else><div class="flex h-9 items-center gap-2 border-b px-5 text-xs">- <div class="flex overflow-hidden rounded-md border bg-muted/20 p-0.5">- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': memberValueView === 'json' }" @click="memberValueView = 'json'">- <Braces class="h-3.5 w-3.5" />- {{ t("redis.jsonView") }}- </Button>- <Button variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :class="{ 'bg-background shadow-sm': memberValueView === 'raw' }" @click="memberValueView = 'raw'">- <FileText class="h-3.5 w-3.5" />- {{ t("redis.rawContent") }}+ <div class="flex max-w-full overflow-x-auto rounded-md border bg-muted/20 p-0.5">+ <Button+ v-for="format in REDIS_VALUE_FORMAT_DISPLAY_ORDER"+ :key="format"+ variant="ghost"+ size="sm"+ class="h-6 shrink-0 rounded-[5px] px-2 text-xs"+ :class="{ 'bg-background shadow-sm': memberValueView === format }"+ :disabled="!canRenderRedisValueFormat(selectedMemberDetail, format)"+ @click="setMemberValueFormat(format)"+ >+ {{ redisFormatLabel(format, selectedMemberDetail.rawLabel) }}</Button></div><span class="flex-1" />- <Button v-if="memberValueView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.formatJson')" @click="handleFormatMemberJson">- <IndentIncrease class="h-3.5 w-3.5" />- </Button>- <Button v-if="memberValueView === 'raw'" variant="ghost" size="sm" class="h-6 rounded-[5px] px-2 text-xs" :title="t('redis.compressJson')" @click="handleCompressMemberJson">- <IndentDecrease class="h-3.5 w-3.5" />- </Button>- <label class="flex items-center gap-1.5 text-muted-foreground">+ <label v-if="isTextRedisFormat(memberValueView)" class="flex items-center gap-1.5 text-muted-foreground"><WrapText class="h-3.5 w-3.5" />{{ t("redis.wordWrap") }}<Switch size="sm" :model-value="redisJsonWordWrap" @update:model-value="setRedisJsonWordWrap(Boolean($event))" /></label></div>- <div v-if="memberValueView === 'json'" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-5 text-[13px] leading-6">- <RedisJsonTree :value="selectedMemberJsonDetail.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />+ <div v-if="memberValueView === 'json' && selectedMemberDetail.json" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-5 text-[13px] leading-6">+ <RedisJsonTree :value="selectedMemberDetail.json.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />+ </div>+ <div v-else-if="memberValueView === 'javaserialize' && selectedMemberDetail.javaSerialized" class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-5 text-[13px] leading-6">+ <RedisJsonTree :value="selectedMemberDetail.javaSerialized.value" :word-wrap="redisJsonWordWrap" :highlight-json="highlightRedisJson" />+ </div>+ <div v-else-if="memberValueView === 'hex'" class="min-h-0 flex-1 overflow-auto bg-background p-5 text-xs leading-5">+ <div class="mb-3 flex items-center justify-between text-muted-foreground">+ <span>{{ t("grid.hexViewer") }}</span>+ <span>{{ t("grid.hexViewerByteCount", { count: selectedMemberDetail.byteCount }) }}</span>+ </div>+ <pre v-if="selectedMemberDetail.hexRows.length > 0" class="dbx-editor-font-family w-full min-w-0 max-w-full select-all whitespace-pre-wrap break-all">{{ detailTextForFormat(selectedMemberDetail, "hex") }}</pre>+ <div v-else class="text-muted-foreground">{{ t("grid.hexViewerEmpty") }}</div></div>- <pre v-else class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-5 text-[13px] leading-6" :class="redisJsonWordWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre'" v-html="memberRawJsonHtml"></pre>+ <pre v-else-if="memberValueView === 'base64'" class="dbx-editor-font-family min-h-0 w-full min-w-0 max-w-full flex-1 overflow-auto bg-background p-5 text-[13px] leading-6 whitespace-pre-wrap break-all">{{ selectedMemberDetail.base64Text }}</pre>+ <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-5 text-[13px] leading-6" :class="detailTextClass(memberValueView)">{{ detailTextForFormat(selectedMemberDetail, memberValueView) }}</pre></template>- <pre v-else class="dbx-editor-font-family min-h-0 flex-1 overflow-auto bg-background p-5 text-[13px] leading-6 whitespace-pre-wrap break-words">{{ selectedMemberDetail.text }}</pre><SheetFooter class="shrink-0 border-t px-5 py-3"><template v-if="isEditingMember"><Button variant="ghost" :disabled="savingMember" @click="cancelEditMember">@@ -1273,11 +1543,11 @@ onBeforeUnmount(() => {{{ t("grid.save") }}</Button></template>- <Button v-else-if="selectedMemberCanEdit" variant="outline" @click="startEditMember">+ <Button v-else-if="canEditCurrentMemberFormat" variant="outline" @click="startEditMember"><Pencil class="h-4 w-4" />{{ t("redis.editMember") }}</Button>- <Button variant="outline" @click="copyText(selectedMemberDetail.rawText)">+ <Button variant="outline" @click="copyText(detailTextForFormat(selectedMemberDetail, memberValueView))"><Copy class="h-4 w-4" />{{ t("redis.copyMember") }}</Button>diff --git a/apps/desktop/src/lib/__tests__/redis/redisValuePresentation.spec.ts b/apps/desktop/src/lib/__tests__/redis/redisValuePresentation.spec.tsindex f02fdf089f..edeb7e4195 100644--- a/apps/desktop/src/lib/__tests__/redis/redisValuePresentation.spec.ts+++ b/apps/desktop/src/lib/__tests__/redis/redisValuePresentation.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { formatRedisMemberDetail, formatRedisStringValue, getRedisMemberSelectionKey, sanitizeRedisDisplayText } from "@/lib/redis/redisValuePresentation";+import { canRenderRedisValueFormat, formatRedisMemberDetail, formatRedisStringValue, getRedisMemberSelectionKey, preferredRedisValueFormat, redisMemberCopyText, sanitizeRedisDisplayText } from "@/lib/redis/redisValuePresentation";describe("redisValuePresentation", () => {it("strips control bytes from display without mutating raw member text", () => {@@ -26,7 +26,119 @@ describe("redisValuePresentation", () => {expect(getRedisMemberSelectionKey("member", raw)).toBe(`member\n${raw}`);});+ it("can disambiguate duplicate stream fields with an explicit identity", () => {+ expect(getRedisMemberSelectionKey("event", "login", "stream:1:0")).not.toBe(getRedisMemberSelectionKey("event", "login", "stream:1:1"));+ });+it("formats string values for display without changing plain text", () => {expect(formatRedisStringValue("plain-text")).toBe("plain-text");});++ it("labels raw text views by encoding instead of generic raw text", () => {+ expect(formatRedisMemberDetail("plain-text").rawLabel).toBe("ASCII");+ expect(+ formatRedisMemberDetail({+ raw_base64: Buffer.from("你好", "utf8").toString("base64"),+ encoding: "utf8",+ }).rawLabel,+ ).toBe("UTF-8");+ expect(+ formatRedisMemberDetail({+ raw_base64: "rO0ABQ==",+ encoding: "binary",+ }).rawLabel,+ ).toBe("Binary");+ });++ it("orders supported formats with the recommended view first", () => {+ expect(+ formatRedisMemberDetail({+ raw_base64: Buffer.from('{"id":1}', "utf8").toString("base64"),+ encoding: "utf8",+ }).availableFormats,+ ).toEqual(["utf8", "ascii", "binary", "hex", "base64"]);+ expect(+ formatRedisMemberDetail({+ raw_base64: "rO0ABQ==",+ encoding: "binary",+ }).availableFormats,+ ).toEqual(["hex", "binary", "base64"]);+ });++ it("keeps a UTF-8 decoding available even for binary blobs", () => {+ const detail = formatRedisMemberDetail({+ raw_base64: "rO0ABQ==",+ encoding: "binary",+ });++ expect(detail.utf8Text).toBe(new TextDecoder("utf-8").decode(Uint8Array.from([0xac, 0xed, 0x00, 0x05])));+ });++ it("only exposes JSON view when payload text explicitly opts in", () => {+ expect(+ formatRedisMemberDetail(+ {+ raw_base64: Buffer.from('{"id":1}', "utf8").toString("base64"),+ encoding: "utf8",+ },+ { allowJsonText: true },+ ).availableFormats,+ ).toEqual(["utf8", "ascii", "binary", "json", "hex", "base64"]);+ });++ it("falls back to utf8 when a binary inspection view was stored for editable text", () => {+ const blob = {+ raw_base64: Buffer.from("Ada", "utf8").toString("base64"),+ encoding: "utf8" as const,+ };++ expect(preferredRedisValueFormat(blob, "hex")).toBe("utf8");+ expect(preferredRedisValueFormat(blob, "base64")).toBe("utf8");+ expect(preferredRedisValueFormat(blob, "binary")).toBe("utf8");+ expect(preferredRedisValueFormat(blob, "json", { allowJsonText: true })).toBe("utf8");+ });++ it("adds a Java serialized format when the blob uses Java object serialization", () => {+ const detail = formatRedisMemberDetail({+ raw_base64: "rO0ABXQACHNvbWV0ZXh0",+ encoding: "binary",+ });++ expect(detail.availableFormats).toEqual(["javaserialize", "binary", "hex", "base64"]);+ expect(detail.defaultFormat).toBe("javaserialize");+ expect(detail.javaSerialized?.formattedText).toBe('"sometext"');+ expect(canRenderRedisValueFormat(detail, "javaserialize")).toBe(true);+ expect(canRenderRedisValueFormat(formatRedisMemberDetail("plain-text"), "javaserialize")).toBe(false);+ });++ it("keeps self-referential Java maps representable via refs", () => {+ const detail = formatRedisMemberDetail({+ raw_base64: "rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAABdAAEc2VsZnEAfgABeA==",+ encoding: "binary",+ });++ const normalized = detail.javaSerialized?.value as { map?: { $entries?: Array<{ value?: { $ref?: string } }> } } | undefined;+ const entries = normalized?.map?.$entries;+ expect(entries?.[0]?.value?.$ref).toBe("#1");+ });++ it("keeps editable text round-trippable while exposing separate ascii/binary views", () => {+ const detail = formatRedisMemberDetail({+ raw_base64: Buffer.from("send_message_to_esb\x06\x16", "latin1").toString("base64"),+ encoding: "utf8",+ });++ expect(detail.rawText).toBe("send_message_to_esb\x06\x16");+ expect(detail.asciiText).toBe("send_message_to_esb\\x06\\x16");+ expect(detail.binaryText).toBe("011100110110010101101110011001000101111101101101011001010111001101110011011000010110011101100101010111110111010001101111010111110110010101110011011000100000011000010110");+ });++ it("copies binary blobs as escaped raw bytes", () => {+ expect(+ redisMemberCopyText({+ raw_base64: "rO0ABQ==",+ encoding: "binary",+ }),+ ).toBe("\\xac\\xed\\x00\\x05");+ });});diff --git a/apps/desktop/src/lib/backend/api.ts b/apps/desktop/src/lib/backend/api.tsindex de070530a5..3e348a8876 100644--- a/apps/desktop/src/lib/backend/api.ts+++ b/apps/desktop/src/lib/backend/api.ts@@ -471,9 +471,18 @@ export type {WebDavDownloadResult,McpServerStatus,UpdateInfo,+ RedisBlob,+ RedisCollectionPage,RedisDatabaseInfo,+ RedisHashItem,RedisKeyInfo,+ RedisListItem,+ RedisSetItem,+ RedisStreamEntry,+ RedisStreamField,RedisValue,+ RedisValueData,+ RedisZsetItem,RedisScanResult,RedisCommandSafety,RedisCommandResult,diff --git a/apps/desktop/src/lib/backend/http.ts b/apps/desktop/src/lib/backend/http.tsindex c3c19f5235..1382252a3b 100644--- a/apps/desktop/src/lib/backend/http.ts+++ b/apps/desktop/src/lib/backend/http.ts@@ -52,6 +52,7 @@ import type {JavaRuntimeConfig,UpdateInfo,UpdateDownloadSource,+ RedisCollectionPage,RedisDatabaseInfo,RedisValue,RedisScanResult,@@ -1727,7 +1728,7 @@ export async function redisExecuteCommand(connectionId: string, db: number, commreturn post("/api/redis/execute-command", { connectionId, db, command, skipSafetyCheck: skipSafetyCheck ?? false });}-export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisValue> {+export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisCollectionPage> {return post("/api/redis/load-more", { connectionId, db, keyRaw, keyType, cursor, count, filter });}diff --git a/apps/desktop/src/lib/backend/tauri.ts b/apps/desktop/src/lib/backend/tauri.tsindex cb61525ef2..7c12f10acf 100644--- a/apps/desktop/src/lib/backend/tauri.ts+++ b/apps/desktop/src/lib/backend/tauri.ts@@ -1303,17 +1303,62 @@ export interface RedisDatabaseInfo {keys: number;}+export type RedisBlobEncoding = "utf8" | "binary";++export interface RedisBlob {+ raw_base64: string;+ encoding: RedisBlobEncoding;+}++export interface RedisListItem {+ index: number;+ value: RedisBlob;+}++export interface RedisSetItem {+ member: RedisBlob;+}++export interface RedisHashItem {+ field: RedisBlob;+ value: RedisBlob;+}++export interface RedisZsetItem {+ score: string;+ member: RedisBlob;+}++export interface RedisStreamField {+ field: string;+ value: string;+}++export interface RedisStreamEntry {+ id: string;+ fields: RedisStreamField[];+}++export type RedisValueData =+ | { kind: "string"; content: RedisBlob }+ | { kind: "json"; value: unknown }+ | { kind: "list"; items: RedisListItem[]; total: number; scan_cursor?: number }+ | { kind: "set"; items: RedisSetItem[]; total: number; scan_cursor?: number }+ | { kind: "hash"; items: RedisHashItem[]; total: number; scan_cursor?: number }+ | { kind: "zset"; items: RedisZsetItem[]; total: number; scan_cursor?: number }+ | { kind: "stream"; entries: RedisStreamEntry[] }+ | { kind: "unknown" };+export interface RedisValue {key_display: string;key_raw: string;- key_type: string;ttl: number;- value_is_binary: boolean;- value: any;- total?: number;- scan_cursor?: number;+ redis_type: string;+ data: RedisValueData;}+export type RedisCollectionPage = { kind: "list"; items: RedisListItem[]; scan_cursor?: number } | { kind: "set"; items: RedisSetItem[]; scan_cursor?: number } | { kind: "hash"; items: RedisHashItem[]; scan_cursor?: number } | { kind: "zset"; items: RedisZsetItem[]; scan_cursor?: number };+export interface RedisScanResult {cursor: number;keys: RedisKeyInfo[];@@ -1434,7 +1479,7 @@ export async function redisExecuteCommand(connectionId: string, db: number, commreturn invoke("redis_execute_command", { connectionId, db, command, skipSafetyCheck: skipSafetyCheck ?? false });}-export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisValue> {+export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisCollectionPage> {return invoke("redis_load_more", { connectionId, db, keyRaw, keyType, cursor, count, filter });}diff --git a/apps/desktop/src/lib/redis/javaSerialized.ts b/apps/desktop/src/lib/redis/javaSerialized.tsnew file mode 100644index 0000000000..8cec4ec67f--- /dev/null+++ b/apps/desktop/src/lib/redis/javaSerialized.ts@@ -0,0 +1,559 @@+export interface RedisJavaSerializedDetail {+ formattedText: string;+ value: unknown;+}++type JavaFieldDescriptor = {+ type: string;+ name: string;+ className?: string;+};++type JavaClassDescriptor = {+ name: string;+ serialVersionUID: string;+ flags: number;+ isEnum: boolean;+ fields: JavaFieldDescriptor[];+ superClass: JavaClassDescriptor | null;+};++type JavaObjectValue = Record<string, unknown> & {+ [JAVA_CLASS_META]?: JavaClassDescriptor;+ [JAVA_EXTENDS_META]?: Record<string, Record<string, unknown>>;+};++type JavaPostProcessor = (fields: Record<string, unknown>, annotations: unknown[]) => Record<string, unknown>;++const JAVA_CLASS_META = Symbol("javaClassMeta");+const JAVA_EXTENDS_META = Symbol("javaExtendsMeta");+const STREAM_MAGIC = 0xaced;+const STREAM_VERSION = 5;+const BASE_WIRE_HANDLE = 0x7e0000;+const END_BLOCK = Symbol("endBlock");++const TAG_NAMES: Record<number, string> = {+ 0x70: "Null",+ 0x71: "Reference",+ 0x72: "ClassDesc",+ 0x73: "Object",+ 0x74: "String",+ 0x75: "Array",+ 0x76: "Class",+ 0x77: "BlockData",+ 0x78: "EndBlockData",+ 0x79: "Reset",+ 0x7a: "BlockDataLong",+ 0x7b: "Exception",+ 0x7c: "LongString",+ 0x7d: "ProxyClassDesc",+ 0x7e: "Enum",+};++const JAVA_POST_PROCESSORS = new Map<string, JavaPostProcessor>([+ ["java.util.ArrayList@7881d21d99c7619d", (fields, annotations) => ({ ...fields, list: annotations.slice(1) })],+ ["java.util.ArrayDeque@207cda2e240da08b", (fields, annotations) => ({ ...fields, list: annotations.slice(1) })],+ ["java.util.Hashtable@13bb0f25214ae4b8", mapPostProcessor],+ ["java.util.HashMap@0507dac1c31660d1", mapPostProcessor],+ ["java.util.HashMap@0507b0c1331660d1", mapPostProcessor],+ ["java.util.EnumMap@065d7df7be907ca1", enumMapPostProcessor],+ ["java.util.HashSet@ba44859596b8b734", hashSetPostProcessor],+]);++export function parseJavaSerializedDetail(bytes: Uint8Array): RedisJavaSerializedDetail | null {+ if (!isJavaSerialized(bytes)) return null;++ try {+ const parser = new JavaSerializationParser(bytes);+ const contents = parser.parseContents();+ if (contents.length === 0) return null;+ const root = contents.length === 1 ? contents[0] : contents;+ const normalized = normalizeJavaSerializedValue(root, new WeakMap<object, string>(), { nextId: 1 });+ return {+ value: normalized,+ formattedText: JSON.stringify(normalized, null, 2),+ };+ } catch {+ return null;+ }+}++export function isJavaSerialized(bytes: Uint8Array): boolean {+ return bytes.length >= 4 && bytes[0] === 0xac && bytes[1] === 0xed && bytes[2] === 0x00 && bytes[3] === 0x05;+}++class JavaSerializationParser {+ private readonly view: DataView;+ private position = 0;+ private nextHandle = BASE_WIRE_HANDLE;+ private readonly handles = new Map<number, unknown>();++ constructor(private readonly bytes: Uint8Array) {+ this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ }++ parseContents(): unknown[] {+ if (this.readUint16() !== STREAM_MAGIC) throw new Error("STREAM_MAGIC not found");+ if (this.readUint16() !== STREAM_VERSION) throw new Error("Only understand protocol version 5");++ const contents: unknown[] = [];+ while (this.position < this.bytes.length) {+ contents.push(this.readContent());+ }+ return contents;+ }++ private readContent(allowed?: string[]): unknown {+ const tag = this.readUint8();+ const name = TAG_NAMES[tag];+ if (!name) throw new Error(`Don't know about type 0x${tag.toString(16)}`);+ if (allowed && !allowed.includes(name)) throw new Error(`${name} not allowed here`);++ switch (tag) {+ case 0x70:+ return null;+ case 0x71:+ return this.readReference();+ case 0x72:+ return this.readClassDescriptor();+ case 0x73:+ return this.readObject();+ case 0x74:+ return this.addHandle(this.readUtf());+ case 0x75:+ return this.readArray();+ case 0x76:+ return this.addHandle(this.readClassDesc());+ case 0x77:+ return this.readBytes(this.readUint8());+ case 0x78:+ return END_BLOCK;+ case 0x79:+ case 0x7b:+ case 0x7d:+ throw new Error(`Don't know how to handle ${name}`);+ case 0x7a:+ return this.readBytes(this.readUint32());+ case 0x7c:+ return this.addHandle(this.readUtfLong());+ case 0x7e:+ return this.readEnum();+ default:+ throw new Error(`Don't know how to handle ${name}`);+ }+ }++ private readClassDesc(): JavaClassDescriptor | null {+ return this.readContent(["ClassDesc", "ProxyClassDesc", "Null", "Reference"]) as JavaClassDescriptor | null;+ }++ private readClassDescriptor(): JavaClassDescriptor {+ const descriptor: JavaClassDescriptor = {+ name: this.readUtf(),+ serialVersionUID: bytesToHex(this.readBytes(8)),+ flags: 0,+ isEnum: false,+ fields: [],+ superClass: null,+ };+ this.addHandle(descriptor);++ descriptor.flags = this.readUint8();+ descriptor.isEnum = Boolean(descriptor.flags & 0x10);+ const count = this.readUint16();+ for (let index = 0; index < count; index += 1) {+ descriptor.fields.push(this.readFieldDescriptor());+ }+ this.readAnnotations();+ descriptor.superClass = this.readClassDesc();+ return descriptor;+ }++ private readFieldDescriptor(): JavaFieldDescriptor {+ const type = String.fromCharCode(this.readUint8());+ const field: JavaFieldDescriptor = { type, name: this.readUtf() };+ if (type === "[" || type === "L") {+ const className = this.readContent();+ field.className = typeof className === "string" ? className : String(className ?? "");+ }+ return field;+ }++ private readObject(): JavaObjectValue {+ const classDescriptor = this.readClassDesc();+ if (!classDescriptor) throw new Error("Object must have a class descriptor");++ const value: JavaObjectValue = {};+ Object.defineProperty(value, JAVA_CLASS_META, { value: classDescriptor, configurable: true });+ Object.defineProperty(value, JAVA_EXTENDS_META, { value: {}, configurable: true });+ this.addHandle(value);+ this.readClassDataRecursive(classDescriptor, value);+ return value;+ }++ private readClassDataRecursive(classDescriptor: JavaClassDescriptor, value: JavaObjectValue) {+ if (classDescriptor.superClass) {+ this.readClassDataRecursive(classDescriptor.superClass, value);+ }++ const fields = this.readClassData(classDescriptor);+ value[JAVA_EXTENDS_META]![classDescriptor.name] = fields;+ for (const [name, fieldValue] of Object.entries(fields)) {+ value[name] = fieldValue;+ }+ }++ private readClassData(classDescriptor: JavaClassDescriptor): Record<string, unknown> {+ const flags = classDescriptor.flags & 0x0f;+ const postProcessor = JAVA_POST_PROCESSORS.get(`${classDescriptor.name}@${classDescriptor.serialVersionUID}`);++ if (flags === 0x02) return this.readFieldValues(classDescriptor);+ if (flags === 0x03) {+ const fields = this.readFieldValues(classDescriptor);+ const annotations = this.readAnnotations();+ fields["@"] = annotations;+ return postProcessor ? postProcessor(fields, annotations) : fields;+ }+ if (flags === 0x04) throw new Error("Can't parse version 1 external content");+ if (flags === 0x0c) {+ const annotations = this.readAnnotations();+ return { "@": annotations };+ }+ throw new Error(`Don't know how to deserialize class with flags 0x${classDescriptor.flags.toString(16)}`);+ }++ private readArray(): unknown[] {+ const classDescriptor = this.readClassDesc();+ if (!classDescriptor) throw new Error("Array must have a class descriptor");++ const value: unknown[] = [];+ Object.defineProperty(value, JAVA_CLASS_META, { value: classDescriptor, configurable: true });+ this.addHandle(value);++ const length = this.readInt32();+ const reader = this.primitiveReader(classDescriptor.name.charAt(1));+ for (let index = 0; index < length; index += 1) {+ value.push(reader());+ }+ return value;+ }++ private readEnum(): unknown {+ const classDescriptor = this.readClassDesc();+ if (!classDescriptor) throw new Error("Enum must have a class descriptor");++ const assignHandle = this.reserveHandle();+ const constant = this.readContent();+ const value = new String(typeof constant === "string" ? constant : String(constant ?? ""));+ Object.defineProperty(value, JAVA_CLASS_META, { value: classDescriptor, configurable: true });+ assignHandle(value);+ return value;+ }++ private readAnnotations(): unknown[] {+ const annotations: unknown[] = [];+ while (true) {+ const value = this.readContent();+ if (value === END_BLOCK) return annotations;+ annotations.push(value);+ }+ }++ private readFieldValues(classDescriptor: JavaClassDescriptor): Record<string, unknown> {+ const values: Record<string, unknown> = {};+ for (const field of classDescriptor.fields) {+ values[field.name] = this.primitiveReader(field.type)();+ }+ return values;+ }++ private primitiveReader(type: string): () => unknown {+ switch (type) {+ case "B":+ return () => this.readInt8();+ case "C":+ return () => String.fromCharCode(this.readUint16());+ case "D":+ return () => this.readFloat64();+ case "F":+ return () => this.readFloat32();+ case "I":+ return () => this.readInt32();+ case "J":+ return () => this.readInt64();+ case "S":+ return () => this.readInt16();+ case "Z":+ return () => this.readInt8() !== 0;+ case "L":+ case "[":+ return () => this.readContent();+ default:+ throw new Error(`Don't know how to read field of type '${type}'`);+ }+ }++ private addHandle<T>(value: T): T {+ this.handles.set(this.nextHandle, value);+ this.nextHandle += 1;+ return value;+ }++ private reserveHandle(): (value: unknown) => void {+ const handle = this.nextHandle;+ this.nextHandle += 1;+ this.handles.set(handle, null);+ return (value: unknown) => {+ this.handles.set(handle, value);+ };+ }++ private readReference(): unknown {+ const handle = this.readInt32();+ if (!this.handles.has(handle)) throw new Error(`Unknown reference handle 0x${handle.toString(16)}`);+ return this.handles.get(handle);+ }++ private readUint8(): number {+ const position = this.step(1);+ return this.view.getUint8(position);+ }++ private readInt8(): number {+ const position = this.step(1);+ return this.view.getInt8(position);+ }++ private readUint16(): number {+ const position = this.step(2);+ return this.view.getUint16(position, false);+ }++ private readInt16(): number {+ const position = this.step(2);+ return this.view.getInt16(position, false);+ }++ private readUint32(): number {+ const position = this.step(4);+ return this.view.getUint32(position, false);+ }++ private readInt32(): number {+ const position = this.step(4);+ return this.view.getInt32(position, false);+ }++ private readInt64(): bigint {+ const high = this.readUint32();+ const low = this.readUint32();+ let value = (BigInt(high) << 32n) | BigInt(low);+ if (high & 0x80000000) {+ value -= 1n << 64n;+ }+ return value;+ }++ private readFloat32(): number {+ const position = this.step(4);+ return this.view.getFloat32(position, false);+ }++ private readFloat64(): number {+ const position = this.step(8);+ return this.view.getFloat64(position, false);+ }++ private readUtf(): string {+ return decodeModifiedUtf8(this.readBytes(this.readUint16()));+ }++ private readUtfLong(): string {+ const high = this.readUint32();+ if (high !== 0) throw new Error("Can't handle more than 2^32 bytes in a string");+ return decodeModifiedUtf8(this.readBytes(this.readUint32()));+ }++ private readBytes(length: number): Uint8Array {+ const position = this.step(length);+ return this.bytes.slice(position, position + length);+ }++ private step(length: number): number {+ const position = this.position;+ this.position += length;+ if (this.position > this.bytes.length) {+ throw new Error("Premature end of input");+ }+ return position;+ }+}++function normalizeJavaSerializedValue(value: unknown, seen: WeakMap<object, string>, state: { nextId: number }): unknown {+ if (value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {+ return value;+ }+ if (typeof value === "bigint") {+ return value.toString();+ }+ if (value instanceof Uint8Array) {+ return { $blockDataHex: bytesToHex(value) };+ }+ if (value instanceof String) {+ const classDescriptor = getJavaClassDescriptor(value);+ if (!classDescriptor) return value.toString();+ return {+ $class: classDescriptor.name,+ $enum: value.toString(),+ };+ }+ if (typeof value !== "object") {+ return String(value);+ }+ if (seen.has(value)) {+ return { $ref: seen.get(value) };+ }++ const objectId = `#${state.nextId}`;+ state.nextId += 1;+ seen.set(value, objectId);++ const classDescriptor = getJavaClassDescriptor(value);+ const extendsValues = getJavaExtendsValues(value);++ if (value instanceof Map) {+ return {+ $id: objectId,+ ...(classDescriptor ? { $class: classDescriptor.name } : {}),+ $entries: Array.from(value.entries(), ([key, entryValue]) => ({+ key: normalizeJavaSerializedValue(key, seen, state),+ value: normalizeJavaSerializedValue(entryValue, seen, state),+ })),+ };+ }++ if (value instanceof Set) {+ return {+ $id: objectId,+ ...(classDescriptor ? { $class: classDescriptor.name } : {}),+ $values: Array.from(value.values(), (entryValue) => normalizeJavaSerializedValue(entryValue, seen, state)),+ };+ }++ if (Array.isArray(value)) {+ const normalized = {+ $id: objectId,+ ...(classDescriptor ? { $class: classDescriptor.name } : {}),+ $values: value.map((entryValue) => normalizeJavaSerializedValue(entryValue, seen, state)),+ };+ return normalized;+ }++ const normalized: Record<string, unknown> = {+ $id: objectId,+ ...(classDescriptor ? { $class: classDescriptor.name } : {}),+ };++ for (const [name, entryValue] of Object.entries(value as Record<string, unknown>)) {+ normalized[name] = normalizeJavaSerializedValue(entryValue, seen, state);+ }++ if (extendsValues) {+ const classNames = Object.keys(extendsValues);+ if (classNames.length > 1) {+ normalized.$extends = Object.fromEntries(classNames.map((className) => [className, Object.fromEntries(Object.entries(extendsValues[className]).map(([name, entryValue]) => [name, normalizeJavaSerializedValue(entryValue, seen, state)]))]));+ }+ }++ return normalized;+}++function getJavaClassDescriptor(value: object): JavaClassDescriptor | undefined {+ return (value as { [JAVA_CLASS_META]?: JavaClassDescriptor })[JAVA_CLASS_META];+}++function getJavaExtendsValues(value: object): Record<string, Record<string, unknown>> | undefined {+ return (value as { [JAVA_EXTENDS_META]?: Record<string, Record<string, unknown>> })[JAVA_EXTENDS_META];+}++function mapPostProcessor(fields: Record<string, unknown>, annotations: unknown[]): Record<string, unknown> {+ const header = annotations[0];+ if (!(header instanceof Uint8Array)) return fields;++ const size = readInt32FromBytes(header, 4);+ const map = new Map<unknown, unknown>();+ const obj: Record<string, unknown> = {};+ for (let index = 0; index < size; index += 1) {+ const key = annotations[2 * index + 1];+ const value = annotations[2 * index + 2];+ map.set(key, value);+ if (typeof key === "string") {+ obj[key] = value;+ }+ }+ return { ...fields, map, obj };+}++function enumMapPostProcessor(fields: Record<string, unknown>, annotations: unknown[]): Record<string, unknown> {+ const header = annotations[0];+ if (!(header instanceof Uint8Array)) return fields;++ const size = readInt32FromBytes(header, 0);+ const map = new Map<unknown, unknown>();+ const obj: Record<string, unknown> = {};+ for (let index = 0; index < size; index += 1) {+ const key = annotations[2 * index + 1];+ const value = annotations[2 * index + 2];+ map.set(key, value);+ obj[String(key)] = value;+ }+ return { ...fields, map, obj };+}++function hashSetPostProcessor(fields: Record<string, unknown>, annotations: unknown[]): Record<string, unknown> {+ const header = annotations[0];+ if (!(header instanceof Uint8Array)) return fields;++ const size = readInt32FromBytes(header, 8);+ const values = annotations.slice(1);+ if (values.length !== size) return fields;+ return { ...fields, set: new Set(values) };+}++function readInt32FromBytes(bytes: Uint8Array, offset: number): number {+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ return view.getInt32(offset, false);+}++function decodeModifiedUtf8(bytes: Uint8Array): string {+ let output = "";+ for (let index = 0; index < bytes.length; ) {+ const byte = bytes[index];+ if ((byte & 0x80) === 0) {+ output += String.fromCharCode(byte);+ index += 1;+ continue;+ }+ if ((byte & 0xe0) === 0xc0) {+ const next = bytes[index + 1];+ if (next == null) throw new Error("Invalid modified UTF-8 sequence");+ output += String.fromCharCode(((byte & 0x1f) << 6) | (next & 0x3f));+ index += 2;+ continue;+ }+ if ((byte & 0xf0) === 0xe0) {+ const next = bytes[index + 1];+ const third = bytes[index + 2];+ if (next == null || third == null) throw new Error("Invalid modified UTF-8 sequence");+ output += String.fromCharCode(((byte & 0x0f) << 12) | ((next & 0x3f) << 6) | (third & 0x3f));+ index += 3;+ continue;+ }+ throw new Error("Invalid modified UTF-8 sequence");+ }+ return output;+}++function bytesToHex(bytes: Uint8Array): string {+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");+}diff --git a/apps/desktop/src/lib/redis/redisValuePresentation.ts b/apps/desktop/src/lib/redis/redisValuePresentation.tsindex d18a7b00d4..c7554dcc4e 100644--- a/apps/desktop/src/lib/redis/redisValuePresentation.ts+++ b/apps/desktop/src/lib/redis/redisValuePresentation.ts@@ -1,10 +1,30 @@+import type { BinaryHexViewRow } from "@/lib/dataGrid/binaryHexViewer";+import { buildBinaryHexViewRows } from "@/lib/dataGrid/binaryHexViewer";+import type { RedisBlob, RedisCollectionPage, RedisHashItem, RedisListItem, RedisSetItem, RedisValue, RedisZsetItem } from "@/lib/backend/api";+import { parseJavaSerializedDetail, type RedisJavaSerializedDetail } from "@/lib/redis/javaSerialized";++export type RedisValueFormat = "utf8" | "ascii" | "binary" | "json" | "javaserialize" | "hex" | "base64";export type RedisMemberDetailFormat = "json" | "text";+export const REDIS_VALUE_FORMAT_DISPLAY_ORDER: RedisValueFormat[] = ["utf8", "ascii", "binary", "json", "javaserialize", "hex", "base64"];+export interface RedisMemberDetail {text: string;rawText: string;+ rawLabel: string;+ utf8Text: string;+ asciiText: string;+ binaryText: string;format: RedisMemberDetailFormat;json?: RedisJsonDetail;+ javaSerialized?: RedisJavaSerializedDetail;+ availableFormats: RedisValueFormat[];+ defaultFormat: RedisValueFormat;+ byteCount: number;+ base64Text: string;+ hexRows: BinaryHexViewRow[];+ editable: boolean;+ binary: boolean;}export interface RedisJsonDetail {@@ -13,13 +33,20 @@ export interface RedisJsonDetail {value: unknown;}+export interface RedisMemberDetailOptions {+ allowJsonText?: boolean;+}+export type RedisMemberDetailKind = "list" | "set" | "hash" | "zset" | "stream";+export type RedisCollectionItem = RedisListItem | RedisSetItem | RedisHashItem | RedisZsetItem;export const REDIS_MEMBER_DETAIL_SHEET_MIN_WIDTH = 360;export const REDIS_MEMBER_DETAIL_SHEET_MAX_WIDTH = 900;-export function canEditRedisMemberDetail(kind: RedisMemberDetailKind): boolean {- return kind !== "stream";+export function canEditRedisMemberDetail(kind: RedisMemberDetailKind, value?: unknown): boolean {+ if (kind === "stream") return false;+ if (value == null) return true;+ return !isRedisBlob(value) || value.encoding !== "binary";}export function clampRedisMemberDetailSheetWidth(width: number, viewportWidth: number): number {@@ -27,27 +54,97 @@ export function clampRedisMemberDetailSheetWidth(width: number, viewportWidth: nreturn Math.min(Math.min(REDIS_MEMBER_DETAIL_SHEET_MAX_WIDTH, viewportMax), Math.max(REDIS_MEMBER_DETAIL_SHEET_MIN_WIDTH, width));}-export function formatRedisMemberDetail(value: unknown): RedisMemberDetail {+export function isRedisBlob(value: unknown): value is RedisBlob {+ return typeof value === "object" && value !== null && "raw_base64" in value && "encoding" in value;+}++export function decodeRedisBlob(blob: RedisBlob): Uint8Array {+ return base64ToBytes(blob.raw_base64);+}++export function redisBlobText(blob: RedisBlob): string | null {+ if (blob.encoding === "binary") return null;+ return decodeUtf8Bytes(decodeRedisBlob(blob));+}++export function redisBlobRawText(blob: RedisBlob): string {+ return redisBlobText(blob) ?? escapeRedisBytes(decodeRedisBlob(blob));+}++export function redisBlobDisplayText(blob: RedisBlob): string {+ return sanitizeRedisDisplayText(redisBlobRawText(blob));+}++export function formatRedisMemberDetail(value: unknown, options: RedisMemberDetailOptions = {}): RedisMemberDetail {+ if (isRedisBlob(value)) return formatRedisBlobDetail(value, options);+if (typeof value === "string") {- const json = parseRedisJsonDetail(value);- return json ? { text: json.formattedText, rawText: value, format: "json", json } : { text: sanitizeRedisDisplayText(value), rawText: value, format: "text" };+ const bytes = new TextEncoder().encode(value);+ const json = options.allowJsonText ? (parseRedisJsonDetail(value) ?? undefined) : undefined;+ const textFormats: RedisValueFormat[] = ["utf8", "ascii", "binary"];+ return {+ text: sanitizeRedisDisplayText(value),+ rawText: value,+ rawLabel: isAsciiBytes(bytes) ? "ASCII" : "UTF-8",+ utf8Text: value,+ asciiText: asciiBytesToText(bytes),+ binaryText: binaryBytesToText(bytes),+ format: "text",+ json,+ availableFormats: formatOrderForValue("utf8", textFormats, json ? ["json"] : []),+ defaultFormat: "utf8",+ byteCount: bytes.byteLength,+ base64Text: bytesToBase64(bytes),+ hexRows: buildBinaryHexViewRows(bytes),+ editable: true,+ binary: false,+ };}try {const formattedText = JSON.stringify(value, null, 2);+ const bytes = new TextEncoder().encode(formattedText);return {text: formattedText,rawText: formattedText,+ rawLabel: "Raw",+ utf8Text: formattedText,+ asciiText: asciiBytesToText(bytes),+ binaryText: binaryBytesToText(bytes),format: "json",json: { rawText: formattedText, formattedText, value },+ availableFormats: formatOrderForValue("json", ["utf8"], ["json"]),+ defaultFormat: "json",+ byteCount: bytes.byteLength,+ base64Text: bytesToBase64(bytes),+ hexRows: buildBinaryHexViewRows(bytes),+ editable: false,+ binary: false,};} catch {const text = String(value);- return { text, rawText: text, format: "text" };+ const bytes = new TextEncoder().encode(text);+ return {+ text,+ rawText: text,+ rawLabel: "Raw",+ utf8Text: text,+ asciiText: asciiBytesToText(bytes),+ binaryText: binaryBytesToText(bytes),+ format: "text",+ availableFormats: formatOrderForValue("utf8", ["utf8"], []),+ defaultFormat: "utf8",+ byteCount: bytes.byteLength,+ base64Text: bytesToBase64(bytes),+ hexRows: buildBinaryHexViewRows(bytes),+ editable: false,+ binary: false,+ };}}export function formatRedisStringValue(value: unknown): string {+ if (isRedisBlob(value)) return formatRedisMemberDetail(value).text;if (typeof value !== "string") return String(value ?? "");return formatRedisJsonString(value) ?? sanitizeRedisDisplayText(value);}@@ -85,19 +182,13 @@ export function formatRedisConsoleValue(value: unknown): string {return JSON.stringify(value, null, 2);}-function formatRedisJsonString(value: string): string | null {- return parseRedisJsonDetail(value)?.formattedText ?? null;-}-export function parseRedisJsonDetail(value: unknown): RedisJsonDetail | null {if (typeof value !== "string") return null;const trimmed = value.trim();if (!trimmed) return null;- if (!looksLikeJsonContainer(trimmed)) return null;try {const parsed = JSON.parse(trimmed);- if (!isJsonContainer(parsed)) return null;return {rawText: value,formattedText: JSON.stringify(parsed, null, 2),@@ -108,17 +199,175 @@ export function parseRedisJsonDetail(value: unknown): RedisJsonDetail | null {}}-function looksLikeJsonContainer(value: string): boolean {- return (value.startsWith("{") && value.endsWith("}")) || (value.startsWith("[") && value.endsWith("]"));+export function preferredRedisValueFormat(value: unknown, preferred?: RedisValueFormat | null, options: RedisMemberDetailOptions = {}): RedisValueFormat {+ const detail = formatRedisMemberDetail(value, options);+ if (preferred && detail.availableFormats.includes(preferred) && shouldReuseRedisValueFormatPreference(detail, preferred)) return preferred;+ return detail.defaultFormat;}-function isJsonContainer(value: unknown): boolean {- return value !== null && typeof value === "object";+export function canRenderRedisValueFormat(detail: RedisMemberDetail, format: RedisValueFormat): boolean {+ switch (format) {+ case "json":+ return Boolean(detail.json);+ case "javaserialize":+ return Boolean(detail.javaSerialized);+ default:+ return true;+ }}-export function getRedisMemberSelectionKey(title: string, value: unknown): string {+export function redisMemberCopyText(value: unknown): string {+ return isRedisBlob(value) ? redisBlobRawText(value) : formatRedisMemberDetail(value).rawText;+}++export function getRedisMemberSelectionKey(title: string, value: unknown, identity = title): string {+ if (isRedisBlob(value)) return `${identity}\n${value.raw_base64}`;const detail = formatRedisMemberDetail(value);- return `${title}\n${detail.format === "json" ? detail.text : detail.rawText}`;+ return `${identity}\n${detail.rawText}`;+}++export function redisValueCollectionItems(value: RedisValue): RedisCollectionItem[] {+ switch (value.data.kind) {+ case "list":+ case "set":+ case "hash":+ case "zset":+ return value.data.items;+ default:+ return [];+ }+}++export function redisCollectionPageItems(page: RedisCollectionPage): RedisCollectionItem[] {+ return page.items;+}++export function redisValueCollectionTotal(value: RedisValue): number | null {+ switch (value.data.kind) {+ case "list":+ case "set":+ case "hash":+ case "zset":+ return value.data.total;+ default:+ return null;+ }+}++export function redisValueCollectionScanCursor(value: RedisValue): number | undefined {+ switch (value.data.kind) {+ case "list":+ case "set":+ case "hash":+ case "zset":+ return value.data.scan_cursor;+ default:+ return undefined;+ }+}++export function redisValueSize(value: RedisValue): number {+ switch (value.data.kind) {+ case "string":+ return decodeRedisBlob(value.data.content).byteLength;+ case "json":+ return new TextEncoder().encode(JSON.stringify(value.data.value)).byteLength;+ case "list":+ case "set":+ case "hash":+ case "zset":+ return value.data.total;+ case "stream":+ return value.data.entries.length;+ default:+ return 0;+ }+}++export function redisValuePreview(value: RedisValue): string {+ switch (value.data.kind) {+ case "string":+ return previewText(redisBlobRawText(value.data.content));+ case "json":+ return previewText(JSON.stringify(value.data.value));+ case "list": {+ const first = value.data.items[0];+ return first ? previewText(redisBlobRawText(first.value)) : "";+ }+ case "set": {+ const first = value.data.items[0];+ return first ? previewText(redisBlobRawText(first.member)) : "";+ }+ case "hash": {+ const first = value.data.items[0];+ return first ? previewText(`${redisBlobRawText(first.field)} ${redisBlobRawText(first.value)}`) : "";+ }+ case "zset": {+ const first = value.data.items[0];+ return first ? previewText(`${first.score} ${redisBlobRawText(first.member)}`) : "";+ }+ case "stream": {+ const first = value.data.entries[0];+ if (!first) return "";+ const joined = first.fields.map(({ field, value: entryValue }) => `${field} ${entryValue}`).join(" ");+ return previewText(joined);+ }+ default:+ return "";+ }+}++export function redisValueCopyText(value: RedisValue, collectionItems: RedisCollectionItem[] = redisValueCollectionItems(value)): string {+ switch (value.data.kind) {+ case "string":+ return redisBlobRawText(value.data.content);+ case "json":+ return JSON.stringify(value.data.value, null, 2);+ case "list":+ return JSON.stringify(+ (collectionItems as RedisListItem[]).map((item) => redisBlobRawText(item.value)),+ null,+ 2,+ );+ case "set":+ return JSON.stringify(+ (collectionItems as RedisSetItem[]).map((item) => redisBlobRawText(item.member)),+ null,+ 2,+ );+ case "hash":+ return JSON.stringify(+ (collectionItems as RedisHashItem[]).map((item) => ({+ field: redisBlobRawText(item.field),+ value: redisBlobRawText(item.value),+ })),+ null,+ 2,+ );+ case "zset":+ return JSON.stringify(+ (collectionItems as RedisZsetItem[]).map((item) => ({+ score: item.score,+ member: redisBlobRawText(item.member),+ })),+ null,+ 2,+ );+ case "stream":+ return JSON.stringify(+ value.data.entries.map((entry) => ({+ id: entry.id,+ fields: entry.fields.map((field) => ({+ field: field.field,+ value: field.value,+ })),+ })),+ null,+ 2,+ );+ default:+ return JSON.stringify(value.data, null, 2);+ }}export function sanitizeRedisDisplayText(value: string): string {@@ -135,10 +384,6 @@ export function sanitizeRedisDisplayText(value: string): string {return output;}-function isUtf8ControlCharacter(ch: string): boolean {- return /\p{Cc}/u.test(ch);-}-export function highlightRedisJsonDetail(json: string): string {const escaped = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");@@ -150,3 +395,137 @@ export function highlightRedisJsonDetail(json: string): string {return `<span class="${cls}">${match}</span>`;});}++function formatRedisBlobDetail(blob: RedisBlob, options: RedisMemberDetailOptions): RedisMemberDetail {+ const bytes = decodeRedisBlob(blob);+ const strictUtf8Text = blob.encoding === "binary" ? null : decodeUtf8Bytes(bytes);+ const utf8Text = strictUtf8Text ?? decodeUtf8BytesLossy(bytes);+ const asciiText = asciiBytesToText(bytes);+ const binaryText = binaryBytesToText(bytes);+ const rawText = strictUtf8Text ?? binaryText;+ const javaSerialized = parseJavaSerializedDetail(bytes);+ const defaultFormat: RedisValueFormat = javaSerialized ? "javaserialize" : strictUtf8Text != null ? "utf8" : "hex";+ const json = options.allowJsonText && strictUtf8Text != null ? (parseRedisJsonDetail(strictUtf8Text) ?? undefined) : undefined;+ const textFormats: RedisValueFormat[] = strictUtf8Text != null ? ["utf8", "ascii", "binary"] : ["binary"];+ const extraFormats: RedisValueFormat[] = [];+ if (json) extraFormats.push("json");+ if (javaSerialized) extraFormats.push("javaserialize");+ return {+ text: redisBlobDisplayText(blob),+ rawText,+ rawLabel: blob.encoding === "binary" ? "Binary" : isAsciiBytes(bytes) ? "ASCII" : "UTF-8",+ utf8Text,+ asciiText,+ binaryText,+ format: "text",+ json,+ javaSerialized: javaSerialized ?? undefined,+ availableFormats: formatOrderForValue(defaultFormat, textFormats, extraFormats),+ defaultFormat,+ byteCount: bytes.byteLength,+ base64Text: blob.raw_base64,+ hexRows: buildBinaryHexViewRows(bytes),+ editable: strictUtf8Text != null,+ binary: strictUtf8Text == null,+ };+}++function formatRedisJsonString(value: string): string | null {+ return parseRedisJsonDetail(value)?.formattedText ?? null;+}++function formatOrderForValue(defaultFormat: RedisValueFormat, textFormats: RedisValueFormat[], extraFormats: RedisValueFormat[]): RedisValueFormat[] {+ const availableFormats: RedisValueFormat[] = [...textFormats];+ availableFormats.push(...extraFormats);+ availableFormats.push("hex", "base64");+ return [defaultFormat, ...availableFormats.filter((format) => format !== defaultFormat)];+}++function shouldReuseRedisValueFormatPreference(detail: RedisMemberDetail, format: RedisValueFormat): boolean {+ if (!detail.editable) return true;+ return format === "utf8" || format === "json";+}++function previewText(value: string): string {+ const singleLine = value.replace(/\s+/g, " ").trim();+ return singleLine.length > 160 ? `${singleLine.slice(0, 160)}…` : singleLine;+}++function isUtf8ControlCharacter(ch: string): boolean {+ return /\p{Cc}/u.test(ch);+}++function escapeRedisBytes(bytes: Uint8Array): string {+ let output = "";+ for (const byte of bytes) {+ if (byte === 0x5c) {+ output += "\\\\";+ continue;+ }+ if (byte >= 0x20 && byte <= 0x7e) {+ output += String.fromCharCode(byte);+ continue;+ }+ output += `\\x${byte.toString(16).padStart(2, "0")}`;+ }+ return output;+}++function decodeUtf8Bytes(bytes: Uint8Array): string | null {+ try {+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);+ } catch {+ return null;+ }+}++function decodeUtf8BytesLossy(bytes: Uint8Array): string {+ return new TextDecoder("utf-8").decode(bytes);+}++function asciiBytesToText(bytes: Uint8Array): string {+ let output = "";+ for (const byte of bytes) {+ if (byte === 0x0a) {+ output += "\n";+ continue;+ }+ if (byte === 0x0d) {+ output += "\r";+ continue;+ }+ if (byte === 0x09) {+ output += "\t";+ continue;+ }+ if (byte >= 0x20 && byte <= 0x7e) {+ output += String.fromCharCode(byte);+ continue;+ }+ output += `\\x${byte.toString(16).padStart(2, "0")}`;+ }+ return output;+}++function binaryBytesToText(bytes: Uint8Array): string {+ return Array.from(bytes, (byte) => byte.toString(2).padStart(8, "0")).join("");+}++function base64ToBytes(value: string): Uint8Array {+ if (typeof atob !== "function") throw new Error("Base64 decoding is unavailable in this runtime");+ const binary = atob(value);+ return Uint8Array.from(binary, (char) => char.charCodeAt(0));+}++function bytesToBase64(bytes: Uint8Array): string {+ if (typeof btoa !== "function") throw new Error("Base64 encoding is unavailable in this runtime");+ let binary = "";+ bytes.forEach((byte) => {+ binary += String.fromCharCode(byte);+ });+ return btoa(binary);+}++function isAsciiBytes(bytes: Uint8Array): boolean {+ return bytes.every((byte) => byte <= 0x7f);+}diff --git a/crates/dbx-core/src/db/redis_driver.rs b/crates/dbx-core/src/db/redis_driver.rsindex ee2f5aa2d9..f722dba634 100644--- a/crates/dbx-core/src/db/redis_driver.rs+++ b/crates/dbx-core/src/db/redis_driver.rs@@ -64,12 +64,121 @@ pub struct RedisScanResult {pub struct RedisValue {pub key_display: String,pub key_raw: String,- pub key_type: String,pub ttl: i64,- pub value_is_binary: bool,- pub value: serde_json::Value,- pub total: Option<u64>,- pub scan_cursor: Option<u64>,+ pub redis_type: String,+ pub data: RedisValueData,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum RedisBlobEncoding {+ Utf8,+ Binary,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisBlob {+ pub raw_base64: String,+ pub encoding: RedisBlobEncoding,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisListItem {+ pub index: u64,+ pub value: RedisBlob,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisSetItem {+ pub member: RedisBlob,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisHashItem {+ pub field: RedisBlob,+ pub value: RedisBlob,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisZsetItem {+ pub score: String,+ pub member: RedisBlob,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisStreamField {+ pub field: String,+ pub value: String,+}++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct RedisStreamEntry {+ pub id: String,+ pub fields: Vec<RedisStreamField>,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(tag = "kind", rename_all = "snake_case")]+pub enum RedisValueData {+ String {+ content: RedisBlob,+ },+ Json {+ value: serde_json::Value,+ },+ List {+ items: Vec<RedisListItem>,+ total: u64,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Set {+ items: Vec<RedisSetItem>,+ total: u64,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Hash {+ items: Vec<RedisHashItem>,+ total: u64,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Zset {+ items: Vec<RedisZsetItem>,+ total: u64,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Stream {+ entries: Vec<RedisStreamEntry>,+ },+ Unknown,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(tag = "kind", rename_all = "snake_case")]+pub enum RedisCollectionPage {+ List {+ items: Vec<RedisListItem>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Set {+ items: Vec<RedisSetItem>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Hash {+ items: Vec<RedisHashItem>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },+ Zset {+ items: Vec<RedisZsetItem>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ scan_cursor: Option<u64>,+ },}#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]@@ -1701,17 +1810,18 @@ wherelet Ok(value) = get_value(con, &key).await else {continue;};- if !redis_value_matches_query(&value.value, query) {+ if !redis_value_matches_query(&value, query) {continue;}- let value_preview = redis_search_value_preview(&value.value);+ let value_preview = redis_search_value_preview(&value.data);+ let size = redis_search_value_size(&value);result.push(RedisKeyInfo {key_display: value.key_display,key_raw: value.key_raw,- key_type: value.key_type,+ key_type: value.redis_type,ttl: value.ttl,- size: redis_search_value_size(&value.value, value.total),+ size,value_preview,});}@@ -1723,19 +1833,18 @@ pub async fn get_value<C>(con: &mut C, key: &[u8]) -> Result<RedisValue, String>whereC: ConnectionLike + Send + Sync + Unpin,{- let key_type: String = redis::cmd("TYPE").arg(key).query_async(con).await.map_err(|e| e.to_string())?;+ let redis_type: String = redis::cmd("TYPE").arg(key).query_async(con).await.map_err(|e| e.to_string())?;let ttl: i64 = redis::cmd("TTL").arg(key).query_async(con).await.unwrap_or(-1);- let (value, value_is_binary, total, scan_cursor) = match key_type.as_str() {+ let data = match redis_type.as_str() {"string" => {let v: RedisRawValue = redis::cmd("GET").arg(key).query_async(con).await.map_err(|e| e.to_string())?;- let value_is_binary = redis_value_contains_binary(&v);- let value = match v {- RedisRawValue::BulkString(bytes) => json_string_to_js_safe(redis_bytes_to_display(&bytes)),- other => redis_raw_to_json(other),- };- (value, value_is_binary, None, None)+ RedisValueData::String {+ content: redis_value_to_bytes(v)+ .map(|bytes| redis_blob_from_bytes(&bytes))+ .ok_or_else(|| "Redis string payload is not byte-addressable".to_string())?,+ }}"list" => {let len: u64 = redis::cmd("LLEN").arg(key).query_async(con).await.unwrap_or(0);@@ -1743,53 +1852,47 @@ wherelet v: RedisRawValue =redis::cmd("LRANGE").arg(key).arg(0).arg(end).query_async(con).await.map_err(|e| e.to_string())?;let cursor = if len > COLLECTION_PAGE_SIZE as u64 { Some(COLLECTION_PAGE_SIZE as u64) } else { None };- (redis_array_to_json(v), false, Some(len), cursor)+ RedisValueData::List { items: redis_list_items_from_raw(v, 0), total: len, scan_cursor: cursor }}"set" => {let len: u64 = redis::cmd("SCARD").arg(key).query_async(con).await.unwrap_or(0);- let (next_cursor, items) = sscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE).await?;- let cursor = if next_cursor > 0 { Some(next_cursor) } else { None };- (serde_json::Value::Array(items), false, Some(len), cursor)+ let (cursor, items) = sscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE).await?;+ RedisValueData::Set { items, total: len, scan_cursor: (cursor > 0).then_some(cursor) }}"zset" => {let len: u64 = redis::cmd("ZCARD").arg(key).query_async(con).await.unwrap_or(0);- let (next_cursor, items) = zscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE).await?;- let cursor = if next_cursor > 0 { Some(next_cursor) } else { None };- (serde_json::Value::Array(items), false, Some(len), cursor)+ let (cursor, items) = zscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE).await?;+ RedisValueData::Zset { items, total: len, scan_cursor: (cursor > 0).then_some(cursor) }}"hash" => {let len: u64 = redis::cmd("HLEN").arg(key).query_async(con).await.unwrap_or(0);- let (next_cursor, items) = hscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE, None).await?;- let cursor = if next_cursor > 0 { Some(next_cursor) } else { None };- (serde_json::Value::Array(items), false, Some(len), cursor)+ let (cursor, items) = hscan_page_raw(con, key, 0, COLLECTION_PAGE_SIZE, None).await?;+ RedisValueData::Hash { items, total: len, scan_cursor: (cursor > 0).then_some(cursor) }}- "stream" => (get_stream_entries(con, key).await?, false, None, None),+ "stream" => RedisValueData::Stream { entries: get_stream_entries(con, key).await? },key_type if is_redis_json_type(key_type) => {let raw: RedisRawValue =redis::cmd("JSON.GET").arg(key).query_async(con).await.map_err(|e| e.to_string())?;- (redis_json_raw_to_json(raw)?, false, None, None)+ RedisValueData::Json { value: redis_json_raw_to_json(raw)? }}- _ => (serde_json::Value::Null, false, None, None),+ _ => RedisValueData::Unknown,};Ok(RedisValue {key_display: redis_key_bytes_to_display(key),key_raw: redis_key_bytes_to_raw(key),- key_type,+ redis_type,ttl,- value_is_binary,- value,- total,- scan_cursor,+ data,})}-fn redis_value_matches_query(value: &serde_json::Value, query: &str) -> bool {+fn redis_value_matches_query(value: &RedisValue, query: &str) -> bool {let query = query.trim();if query.is_empty() {return false;}- redis_search_value_text(value).to_lowercase().contains(&query.to_lowercase())+ redis_search_value_text(&value.data).to_lowercase().contains(&query.to_lowercase())}fn redis_key_matches_query(key_display: &str, key_raw: &str, query: &str) -> bool {@@ -1801,35 +1904,38 @@ fn redis_key_matches_query(key_display: &str, key_raw: &str, query: &str) -> bookey_display.to_lowercase().contains(&query) || key_raw.to_lowercase().contains(&query)}-fn redis_search_value_text(value: &serde_json::Value) -> String {+fn redis_search_value_text(value: &RedisValueData) -> String {match value {- serde_json::Value::String(text) => text.clone(),- serde_json::Value::Array(arr) => {- // Hash type: [{field: "f1", value: "v1"}, ...] — extract field names and values- if let Some(first) = arr.first() {- if first.get("field").is_some() && first.get("value").is_some() {- let parts: Vec<String> = arr- .iter()- .flat_map(|item| {- let f = item.get("field").and_then(|v| v.as_str()).unwrap_or("");- let v = item.get("value").and_then(|v| v.as_str()).unwrap_or("");- vec![f.to_string(), v.to_string()]- })- .filter(|s| !s.is_empty())- .collect();- return parts.join(" ");- }- }- if arr.is_empty() {- return String::new();- }- serde_json::to_string(&arr).unwrap_or_default()+ RedisValueData::String { content } => redis_blob_display_text(content),+ RedisValueData::Json { value } => serde_json::to_string(value).unwrap_or_else(|_| value.to_string()),+ RedisValueData::List { items, .. } => {+ items.iter().map(|item| redis_blob_display_text(&item.value)).collect::<Vec<_>>().join(" ")+ }+ RedisValueData::Set { items, .. } => {+ items.iter().map(|item| redis_blob_display_text(&item.member)).collect::<Vec<_>>().join(" ")}- other => serde_json::to_string(other).unwrap_or_else(|_| other.to_string()),+ RedisValueData::Hash { items, .. } => items+ .iter()+ .flat_map(|item| [redis_blob_display_text(&item.field), redis_blob_display_text(&item.value)])+ .collect::<Vec<_>>()+ .join(" "),+ RedisValueData::Zset { items, .. } => items+ .iter()+ .flat_map(|item| [item.score.clone(), redis_blob_display_text(&item.member)])+ .collect::<Vec<_>>()+ .join(" "),+ RedisValueData::Stream { entries } => entries+ .iter()+ .flat_map(|entry| {+ entry.fields.iter().flat_map(|field| [field.field.clone(), field.value.clone()]).collect::<Vec<_>>()+ })+ .collect::<Vec<_>>()+ .join(" "),+ RedisValueData::Unknown => String::new(),}}-fn redis_search_value_preview(value: &serde_json::Value) -> String {+fn redis_search_value_preview(value: &RedisValueData) -> String {const MAX_PREVIEW_LEN: usize = 160;let text = redis_search_value_text(value);if text.chars().count() <= MAX_PREVIEW_LEN {@@ -1840,17 +1946,23 @@ fn redis_search_value_preview(value: &serde_json::Value) -> String {preview}-fn redis_search_value_size(value: &serde_json::Value, total: Option<u64>) -> u64 {- if let Some(total) = total {- return total;- }- match value {- serde_json::Value::String(text) => text.len() as u64,- _ => 0,+fn redis_search_value_size(value: &RedisValue) -> u64 {+ match &value.data {+ RedisValueData::String { content } => base64::engine::general_purpose::STANDARD+ .decode(&content.raw_base64)+ .map(|bytes| bytes.len() as u64)+ .unwrap_or(0),+ RedisValueData::Json { value } => serde_json::to_vec(value).map(|bytes| bytes.len() as u64).unwrap_or(0),+ RedisValueData::List { total, .. }+ | RedisValueData::Set { total, .. }+ | RedisValueData::Hash { total, .. }+ | RedisValueData::Zset { total, .. } => *total,+ RedisValueData::Stream { entries } => entries.len() as u64,+ RedisValueData::Unknown => 0,}}-async fn get_stream_entries<C>(con: &mut C, key: &[u8]) -> Result<serde_json::Value, String>+async fn get_stream_entries<C>(con: &mut C, key: &[u8]) -> Result<Vec<RedisStreamEntry>, String>whereC: ConnectionLike + Send + Sync + Unpin,{@@ -1892,16 +2004,14 @@ fn parse_scan_keys(raw: RedisRawValue) -> Result<(u64, Vec<Vec<u8>>), String> {Ok((cursor, parsed))}-fn parse_stream_entries(raw: RedisRawValue) -> serde_json::Value {+fn parse_stream_entries(raw: RedisRawValue) -> Vec<RedisStreamEntry> {match raw {- RedisRawValue::Array(entries) => {- serde_json::Value::Array(entries.into_iter().filter_map(parse_stream_entry).collect())- }- _ => serde_json::Value::Null,+ RedisRawValue::Array(entries) => entries.into_iter().filter_map(parse_stream_entry).collect(),+ _ => Vec::new(),}}-fn parse_stream_entry(entry: RedisRawValue) -> Option<serde_json::Value> {+fn parse_stream_entry(entry: RedisRawValue) -> Option<RedisStreamEntry> {let mut parts = match entry {RedisRawValue::Array(parts) if parts.len() == 2 => parts.into_iter(),_ => return None,@@ -1913,7 +2023,7 @@ fn parse_stream_entry(entry: RedisRawValue) -> Option<serde_json::Value> {_ => return None,};- let mut field_map = serde_json::Map::new();+ let mut parsed_fields = Vec::new();let mut fields = fields.into_iter();while let Some(field) = fields.next() {let Some(value) = fields.next() else {@@ -1921,14 +2031,11 @@ fn parse_stream_entry(entry: RedisRawValue) -> Option<serde_json::Value> {};if let Some(field_name) = redis_value_to_string(field) {let value = redis_value_to_string(value).unwrap_or_default();- field_map.insert(field_name, json_string_to_js_safe(value));+ parsed_fields.push(RedisStreamField { field: field_name, value });}}- Some(serde_json::json!({- "id": id,- "fields": field_map,- }))+ Some(RedisStreamEntry { id, fields: parsed_fields })}fn redis_value_to_string(value: RedisRawValue) -> Option<String> {@@ -1944,14 +2051,6 @@ fn redis_value_to_string(value: RedisRawValue) -> Option<String> {}}-fn redis_value_contains_binary(value: &RedisRawValue) -> bool {- match value {- RedisRawValue::BulkString(bytes) => std::str::from_utf8(bytes).is_err(),- RedisRawValue::VerbatimString { text, .. } => std::str::from_utf8(text.as_bytes()).is_err(),- _ => false,- }-}-fn redis_value_to_bytes(value: RedisRawValue) -> Option<Vec<u8>> {match value {RedisRawValue::BulkString(bytes) => Some(bytes),@@ -1965,18 +2064,36 @@ fn redis_value_to_bytes(value: RedisRawValue) -> Option<Vec<u8>> {}}-fn redis_array_to_json(value: RedisRawValue) -> serde_json::Value {+fn redis_blob_from_bytes(bytes: &[u8]) -> RedisBlob {+ RedisBlob {+ raw_base64: base64::engine::general_purpose::STANDARD.encode(bytes),+ encoding: if std::str::from_utf8(bytes).is_ok() { RedisBlobEncoding::Utf8 } else { RedisBlobEncoding::Binary },+ }+}++fn redis_blob_display_text(blob: &RedisBlob) -> String {+ let bytes = base64::engine::general_purpose::STANDARD.decode(&blob.raw_base64).unwrap_or_default();+ if matches!(blob.encoding, RedisBlobEncoding::Utf8) {+ if let Ok(text) = std::str::from_utf8(&bytes) {+ return text.to_string();+ }+ }+ redis_bytes_to_display(&bytes)+}++fn redis_list_items_from_raw(value: RedisRawValue, start_index: u64) -> Vec<RedisListItem> {match value {- RedisRawValue::Array(values) => serde_json::Value::Array(- values- .into_iter()- .map(|v| match v {- RedisRawValue::BulkString(bytes) => json_string_to_js_safe(redis_bytes_to_display(&bytes)),- other => redis_raw_to_json(other),+ RedisRawValue::Array(values) => values+ .into_iter()+ .enumerate()+ .filter_map(|(offset, value)| {+ redis_value_to_bytes(value).map(|bytes| RedisListItem {+ index: start_index + offset as u64,+ value: redis_blob_from_bytes(&bytes),})- .collect(),- ),- other => redis_raw_to_json(other),+ })+ .collect(),+ _ => Vec::new(),}}@@ -1988,21 +2105,6 @@ fn redis_raw_to_json(value: RedisRawValue) -> serde_json::Value {}}-/// If the text is JSON (starts with `{` or `[`), parse it, apply-/// `json_value_for_js` (converting large ints to strings), then re-serialize-/// back to a compact JSON string. Otherwise return the text unchanged.-fn json_string_to_js_safe(text: String) -> serde_json::Value {- let trimmed = text.trim();- if trimmed.starts_with('{') || trimmed.starts_with('[') {- if let Ok(json) = serde_json::from_str::<serde_json::Value>(trimmed) {- let safe = json_value_for_js(json);- let re_serialized = serde_json::to_string(&safe).unwrap_or(text);- return serde_json::Value::String(re_serialized);- }- }- serde_json::Value::String(text)-}-fn redis_bytes_to_display(bytes: &[u8]) -> String {if let Ok(text) = std::str::from_utf8(bytes) {return text.replace('\\', "\\\\");@@ -2206,11 +2308,11 @@ pub async fn load_more_collection<C>(cursor: u64,count: usize,filter_query: Option<&str>,-) -> Result<RedisValue, String>+) -> Result<RedisCollectionPage, String>whereC: ConnectionLike + Send + Sync + Unpin,{- let (value, next_cursor) = match key_type {+ match key_type {"list" => {let start = cursor as i64;let end = start + count as i64 - 1;@@ -2218,41 +2320,29 @@ whereredis::cmd("LRANGE").arg(key).arg(start).arg(end).query_async(con).await.map_err(|e| e.to_string())?;let len: u64 = redis::cmd("LLEN").arg(key).query_async(con).await.unwrap_or(0);let next = cursor + count as u64;- let cursor = if next < len { Some(next) } else { None };- (redis_array_to_json(v), cursor)+ Ok(RedisCollectionPage::List {+ items: redis_list_items_from_raw(v, cursor),+ scan_cursor: (next < len).then_some(next),+ })}"set" => {- let (next, items) = sscan_page_raw(con, key, cursor, count).await?;- let cursor = if next > 0 { Some(next) } else { None };- (serde_json::Value::Array(items), cursor)+ let (next_cursor, items) = sscan_page_raw(con, key, cursor, count).await?;+ Ok(RedisCollectionPage::Set { items, scan_cursor: (next_cursor > 0).then_some(next_cursor) })}"zset" => {- let (next, items) = zscan_page_raw(con, key, cursor, count).await?;- let cursor = if next > 0 { Some(next) } else { None };- (serde_json::Value::Array(items), cursor)+ let (next_cursor, items) = zscan_page_raw(con, key, cursor, count).await?;+ Ok(RedisCollectionPage::Zset { items, scan_cursor: (next_cursor > 0).then_some(next_cursor) })}"hash" => {- let (next, items) = if let Some(query) = filter_query.filter(|query| !query.is_empty()) {+ let (next_cursor, items) = if let Some(query) = filter_query.filter(|query| !query.is_empty()) {hscan_filtered_page_raw(con, key, cursor, count, query).await?} else {hscan_page_raw(con, key, cursor, count, None).await?};- let cursor = if next > 0 { Some(next) } else { None };- (serde_json::Value::Array(items), cursor)+ Ok(RedisCollectionPage::Hash { items, scan_cursor: (next_cursor > 0).then_some(next_cursor) })}- _ => return Err(format!("Pagination not supported for type: {key_type}")),- };-- Ok(RedisValue {- key_display: redis_key_bytes_to_display(key),- key_raw: redis_key_bytes_to_raw(key),- key_type: key_type.to_string(),- ttl: -1,- value_is_binary: false,- value,- total: None,- scan_cursor: next_cursor,- })+ _ => Err(format!("Pagination not supported for type: {key_type}")),+ }}async fn hscan_page_raw<C>(@@ -2261,7 +2351,7 @@ async fn hscan_page_raw<C>(cursor: u64,count: usize,match_pattern: Option<&str>,-) -> Result<(u64, Vec<serde_json::Value>), String>+) -> Result<(u64, Vec<RedisHashItem>), String>whereC: ConnectionLike + Send + Sync + Unpin,{@@ -2271,7 +2361,7 @@ wherecmd.arg("MATCH").arg(pattern);}let raw: RedisRawValue = cmd.query_async(con).await.map_err(|e| e.to_string())?;- parse_scan_pairs(raw, "hash")+ parse_scan_hash_entries(raw)}async fn hscan_filtered_page_raw<C>(@@ -2280,7 +2370,7 @@ async fn hscan_filtered_page_raw<C>(cursor: u64,count: usize,query: &str,-) -> Result<(u64, Vec<serde_json::Value>), String>+) -> Result<(u64, Vec<RedisHashItem>), String>whereC: ConnectionLike + Send + Sync + Unpin,{@@ -2302,13 +2392,13 @@ whereOk((cur, items))}-fn hash_entry_matches_query(item: &serde_json::Value, query: &str) -> bool {+fn hash_entry_matches_query(item: &RedisHashItem, query: &str) -> bool {let query = query.to_lowercase();if query.is_empty() {return true;}- let field = item.get("field").and_then(serde_json::Value::as_str).unwrap_or_default();- let value = item.get("value").and_then(serde_json::Value::as_str).unwrap_or_default();+ let field = redis_blob_display_text(&item.field);+ let value = redis_blob_display_text(&item.value);field.to_lowercase().contains(&query) || value.to_lowercase().contains(&query)}@@ -2317,7 +2407,7 @@ async fn sscan_page_raw<C>(key: &[u8],cursor: u64,count: usize,-) -> Result<(u64, Vec<serde_json::Value>), String>+) -> Result<(u64, Vec<RedisSetItem>), String>whereC: ConnectionLike + Send + Sync + Unpin,{@@ -2337,7 +2427,7 @@ async fn zscan_page_raw<C>(key: &[u8],cursor: u64,count: usize,-) -> Result<(u64, Vec<serde_json::Value>), String>+) -> Result<(u64, Vec<RedisZsetItem>), String>whereC: ConnectionLike + Send + Sync + Unpin,{@@ -2349,10 +2439,11 @@ where.query_async(con).await.map_err(|e| e.to_string())?;- parse_scan_pairs(raw, "zset")+ let (next_cursor, items) = parse_scan_pairs(raw)?;+ Ok((next_cursor, items.into_iter().map(|(member, score)| RedisZsetItem { score, member }).collect()))}-fn parse_scan_pairs(raw: RedisRawValue, kind: &str) -> Result<(u64, Vec<serde_json::Value>), String> {+fn parse_scan_pairs(raw: RedisRawValue) -> Result<(u64, Vec<(RedisBlob, String)>), String> {let RedisRawValue::Array(parts) = raw else {return Err("Invalid SCAN response".to_string());};@@ -2373,19 +2464,17 @@ fn parse_scan_pairs(raw: RedisRawValue, kind: &str) -> Result<(u64, Vec<serde_jslet mut iter = entries.iter();while let Some(a) = iter.next() {let Some(b) = iter.next() else { break };- let a_str = redis_value_to_string(a.clone()).unwrap_or_default();- let b = redis_value_to_string(b.clone()).unwrap_or_default();- if kind == "zset" {- items.push(serde_json::json!({"member": a_str, "score": b}));- } else {- items.push(serde_json::json!({"field": a_str, "value": json_string_to_js_safe(b)}));- }+ let member = redis_value_to_bytes(a.clone())+ .map(|bytes| redis_blob_from_bytes(&bytes))+ .ok_or_else(|| "Invalid SCAN member payload".to_string())?;+ let value = redis_value_to_string(b.clone()).unwrap_or_default();+ items.push((member, value));}Ok((cursor, items))}-fn parse_scan_members(raw: RedisRawValue) -> Result<(u64, Vec<serde_json::Value>), String> {+fn parse_scan_hash_entries(raw: RedisRawValue) -> Result<(u64, Vec<RedisHashItem>), String> {let RedisRawValue::Array(parts) = raw else {return Err("Invalid SCAN response".to_string());};@@ -2402,7 +2491,45 @@ fn parse_scan_members(raw: RedisRawValue) -> Result<(u64, Vec<serde_json::Value>return Err("Invalid SCAN entries".to_string());};- let items = entries.iter().filter_map(|v| redis_value_to_string(v.clone())).map(json_string_to_js_safe).collect();+ let mut items = Vec::new();+ let mut iter = entries.iter();+ while let Some(field) = iter.next() {+ let Some(value) = iter.next() else { break };+ let field = redis_value_to_bytes(field.clone())+ .map(|bytes| redis_blob_from_bytes(&bytes))+ .ok_or_else(|| "Invalid hash field payload".to_string())?;+ let value = redis_value_to_bytes(value.clone())+ .map(|bytes| redis_blob_from_bytes(&bytes))+ .ok_or_else(|| "Invalid hash value payload".to_string())?;+ items.push(RedisHashItem { field, value });+ }++ Ok((cursor, items))+}++fn parse_scan_members(raw: RedisRawValue) -> Result<(u64, Vec<RedisSetItem>), String> {+ let RedisRawValue::Array(parts) = raw else {+ return Err("Invalid SCAN response".to_string());+ };+ if parts.len() != 2 {+ return Err("Invalid SCAN response".to_string());+ }++ let cursor = redis_value_to_string(parts[0].clone())+ .ok_or("Invalid cursor")?+ .parse::<u64>()+ .map_err(|_| "Invalid cursor".to_string())?;++ let RedisRawValue::Array(entries) = &parts[1] else {+ return Err("Invalid SCAN entries".to_string());+ };++ let items = entries+ .iter()+ .filter_map(|value| {+ redis_value_to_bytes(value.clone()).map(|bytes| RedisSetItem { member: redis_blob_from_bytes(&bytes) })+ })+ .collect();Ok((cursor, items))}@@ -2414,11 +2541,13 @@ mod tests {use super::{classify_command, connection_info, decode_cluster_cursor, encode_cluster_cursor, is_redis_json_type,parse_cluster_slots, parse_command_argv, parse_database_count, parse_redis_endpoint, parse_scan_keys,- parse_stream_entries, redis_auth_candidates, redis_cluster_slot, redis_command_raw_to_json,- redis_database_index, redis_json_raw_to_json, redis_json_value_preview, redis_key_bytes_to_display,- redis_key_bytes_to_raw, redis_key_matches_query, redis_key_raw_to_bytes, redis_key_value_preview,- redis_raw_to_json, redis_sentinel_master_endpoint, redis_value_contains_binary, redis_value_matches_query,- RedisAuthCandidate, RedisClusterSlotRange, RedisCommandSafety, RedisNodeEndpoint, RedisRawValue,+ parse_stream_entries, redis_auth_candidates, redis_blob_from_bytes, redis_cluster_slot,+ redis_command_raw_to_json, redis_database_index, redis_json_raw_to_json, redis_json_value_preview,+ redis_key_bytes_to_display, redis_key_bytes_to_raw, redis_key_matches_query, redis_key_raw_to_bytes,+ redis_key_value_preview, redis_raw_to_json, redis_sentinel_master_endpoint, redis_value_matches_query,+ redis_value_to_bytes, RedisAuthCandidate, RedisBlob, RedisBlobEncoding, RedisClusterSlotRange,+ RedisCollectionPage, RedisCommandSafety, RedisHashItem, RedisNodeEndpoint, RedisRawValue, RedisSetItem,+ RedisStreamEntry, RedisStreamField, RedisValue, RedisValueData,};use crate::models::connection::ConnectionConfig;use redis::{aio::ConnectionLike, Cmd, ConnectionAddr, Pipeline, RedisFuture};@@ -2478,6 +2607,49 @@ mod tests {RedisRawValue::Array(vec![bulk(cursor), RedisRawValue::Array(entries)])}+ fn text_blob(value: &str) -> RedisBlob {+ redis_blob_from_bytes(value.as_bytes())+ }++ fn redis_value(redis_type: &str, data: RedisValueData) -> RedisValue {+ RedisValue {+ key_display: "test:key".to_string(),+ key_raw: redis_key_bytes_to_raw(b"test:key"),+ ttl: -1,+ redis_type: redis_type.to_string(),+ data,+ }+ }++ fn string_value(value: &str) -> RedisValue {+ redis_value("string", RedisValueData::String { content: text_blob(value) })+ }++ fn hash_value(entries: &[(&str, &str)]) -> RedisValue {+ redis_value(+ "hash",+ RedisValueData::Hash {+ items: entries+ .iter()+ .map(|(field, value)| RedisHashItem { field: text_blob(field), value: text_blob(value) })+ .collect(),+ total: entries.len() as u64,+ scan_cursor: None,+ },+ )+ }++ fn set_value(entries: &[&str]) -> RedisValue {+ redis_value(+ "set",+ RedisValueData::Set {+ items: entries.iter().map(|value| RedisSetItem { member: text_blob(value) }).collect(),+ total: entries.len() as u64,+ scan_cursor: None,+ },+ )+ }+#[test]fn parses_stream_entries() {let raw = RedisRawValue::Array(vec![RedisRawValue::Array(vec![@@ -2489,15 +2661,13 @@ mod tests {assert_eq!(parsed,- serde_json::json!([- {- "id": "1714470000000-0",- "fields": {- "event": "login",- "user_id": "42"- }- }- ])+ vec![RedisStreamEntry {+ id: "1714470000000-0".to_string(),+ fields: vec![+ RedisStreamField { field: "event".to_string(), value: "login".to_string() },+ RedisStreamField { field: "user_id".to_string(), value: "42".to_string() },+ ],+ }]);}@@ -2515,14 +2685,10 @@ mod tests {assert_eq!(parsed,- serde_json::json!([- {- "id": "1714470000001-0",- "fields": {- "event": "logout"- }- }- ])+ vec![RedisStreamEntry {+ id: "1714470000001-0".to_string(),+ fields: vec![RedisStreamField { field: "event".to_string(), value: "logout".to_string() }],+ }]);}@@ -2617,8 +2783,11 @@ mod tests {let result = super::load_more_collection(&mut con, b"hash-key", "hash", 0, 1, Some("user")).await.unwrap();- assert_eq!(result.scan_cursor, Some(512));- assert_eq!(result.value, serde_json::json!([{ "field": "user:1", "value": "Ada" }]));+ let RedisCollectionPage::Hash { items, scan_cursor } = result else {+ panic!("expected hash collection page");+ };+ assert_eq!(scan_cursor, Some(512));+ assert_eq!(items, vec![RedisHashItem { field: text_blob("user:1"), value: text_blob("Ada") }]);assert_eq!(con.command_count("HSCAN"), 1);assert!(!con.commands[0].contains("\r\nMATCH\r\n"));}@@ -2630,8 +2799,11 @@ mod tests {let result = super::load_more_collection(&mut con, b"hash-key", "hash", 0, 20, Some("lovelace")).await.unwrap();- assert_eq!(result.scan_cursor, None);- assert_eq!(result.value, serde_json::json!([{ "field": "status", "value": "Ada Lovelace" }]));+ let RedisCollectionPage::Hash { items, scan_cursor } = result else {+ panic!("expected hash collection page");+ };+ assert_eq!(scan_cursor, None);+ assert_eq!(items, vec![RedisHashItem { field: text_blob("status"), value: text_blob("Ada Lovelace") }]);assert_eq!(con.command_count("HSCAN"), 1);assert!(!con.commands[0].contains("\r\nMATCH\r\n"));}@@ -2645,8 +2817,11 @@ mod tests {let result = super::load_more_collection(&mut con, b"hash-key", "hash", 0, 20, Some("missing")).await.unwrap();- assert_eq!(result.scan_cursor, Some(super::HASH_FILTER_SCAN_MAX_ITERATIONS as u64));- assert_eq!(result.value, serde_json::json!([]));+ let RedisCollectionPage::Hash { items, scan_cursor } = result else {+ panic!("expected hash collection page");+ };+ assert_eq!(scan_cursor, Some(super::HASH_FILTER_SCAN_MAX_ITERATIONS as u64));+ assert!(items.is_empty());assert_eq!(con.command_count("HSCAN"), super::HASH_FILTER_SCAN_MAX_ITERATIONS);}@@ -2663,7 +2838,16 @@ mod tests {fn does_not_treat_utf8_with_backslashes_as_binary() {let raw = RedisRawValue::BulkString(br#"C:\Users\path"#.to_vec());- assert!(!redis_value_contains_binary(&raw));+ let blob = redis_value_to_bytes(raw).map(|bytes| redis_blob_from_bytes(&bytes)).unwrap();+ assert_eq!(blob.encoding, RedisBlobEncoding::Utf8);+ }++ #[test]+ fn preserves_non_ascii_utf8_as_utf8() {+ let raw = RedisRawValue::BulkString("你好,redis".as_bytes().to_vec());++ let blob = redis_value_to_bytes(raw).map(|bytes| redis_blob_from_bytes(&bytes)).unwrap();+ assert_eq!(blob.encoding, RedisBlobEncoding::Utf8);}#[test]@@ -2680,10 +2864,10 @@ mod tests {#[test]fn matches_redis_values_case_insensitively() {- assert!(redis_value_matches_query(&serde_json::json!("Hello Redis"), "redis"));- assert!(redis_value_matches_query(&serde_json::json!({"field": "Ada Lovelace"}), "lovelace"));- assert!(!redis_value_matches_query(&serde_json::json!("Hello Redis"), ""));- assert!(!redis_value_matches_query(&serde_json::json!("Hello Redis"), "mysql"));+ assert!(redis_value_matches_query(&string_value("Hello Redis"), "redis"));+ assert!(redis_value_matches_query(&hash_value(&[("field", "Ada Lovelace")]), "lovelace"));+ assert!(!redis_value_matches_query(&string_value("Hello Redis"), ""));+ assert!(!redis_value_matches_query(&string_value("Hello Redis"), "mysql"));}#[test]@@ -2696,33 +2880,27 @@ mod tests {#[test]fn matches_hash_field_name_in_value_search() {- let hash_value = serde_json::json!([- {"field": "name", "value": "Alice"},- {"field": "email", "value": "[email protected]"},- ]);+ let hash_value = hash_value(&[("name", "Alice"), ("email", "[email protected]")]);assert!(redis_value_matches_query(&hash_value, "name"));assert!(redis_value_matches_query(&hash_value, "email"));}#[test]fn matches_hash_field_value_in_value_search() {- let hash_value = serde_json::json!([- {"field": "name", "value": "Alice"},- {"field": "email", "value": "[email protected]"},- ]);+ let hash_value = hash_value(&[("name", "Alice"), ("email", "[email protected]")]);assert!(redis_value_matches_query(&hash_value, "alice"));assert!(redis_value_matches_query(&hash_value, "example"));}#[test]fn empty_hash_does_not_match() {- let empty_hash = serde_json::json!([]);+ let empty_hash = hash_value(&[]);assert!(!redis_value_matches_query(&empty_hash, "anything"));}#[test]fn non_hash_array_unaffected() {- let set_value = serde_json::json!(["member1", "member2", "hello"]);+ let set_value = set_value(&["member1", "member2", "hello"]);assert!(redis_value_matches_query(&set_value, "member1"));assert!(redis_value_matches_query(&set_value, "hello"));assert!(!redis_value_matches_query(&set_value, "nonexistent"));diff --git a/crates/dbx-core/src/redis_ops.rs b/crates/dbx-core/src/redis_ops.rsindex 5ec77a7a03..5c2bb8f776 100644--- a/crates/dbx-core/src/redis_ops.rs+++ b/crates/dbx-core/src/redis_ops.rs@@ -1,6 +1,7 @@use crate::connection::{AppState, PoolKind};use crate::db::redis_driver::{- self, RedisCommandResult, RedisConnection, RedisDatabaseInfo, RedisKeyInfo, RedisScanResult, RedisValue,+ self, RedisCollectionPage, RedisCommandResult, RedisConnection, RedisDatabaseInfo, RedisKeyInfo, RedisScanResult,+ RedisValue,};async fn ensure_redis_pool(state: &AppState, connection_id: &str) -> Result<(), String> {@@ -790,7 +791,7 @@ pub async fn redis_load_more_in_db_core(cursor: u64,count: usize,filter: Option<&str>,-) -> Result<redis_driver::RedisValue, String> {+) -> Result<RedisCollectionPage, String> {ensure_redis_pool(state, connection_id).await?;let connections = state.connections.read().await;match connections.get(connection_id).ok_or("Not found")? {diff --git a/crates/dbx-core/tests/database_capabilities.rs b/crates/dbx-core/tests/database_capabilities.rsindex 52b72dd8b3..3fe53d2ded 100644--- a/crates/dbx-core/tests/database_capabilities.rs+++ b/crates/dbx-core/tests/database_capabilities.rs@@ -82,7 +82,6 @@ impl DriverProductCapabilities {#[serde(rename_all = "camelCase")]struct DriverProfileEntry {profile: String,- label: String,agent_key: String,}diff --git a/packages/app-tests/redisValuePresentation.test.ts b/packages/app-tests/redisValuePresentation.test.tsindex e6d900a3fd..f04dbec31c 100644--- a/packages/app-tests/redisValuePresentation.test.ts+++ b/packages/app-tests/redisValuePresentation.test.ts@@ -1,20 +1,42 @@import { strict as assert } from "node:assert";import { test } from "vitest";-import { canEditRedisMemberDetail, clampRedisMemberDetailSheetWidth, formatRedisCommandResult, formatRedisMemberDetail, formatRedisStringValue, getRedisMemberSelectionKey, highlightRedisJsonDetail, parseRedisJsonDetail } from "../../apps/desktop/src/lib/redis/redisValuePresentation.ts";+import {+ canRenderRedisValueFormat,+ canEditRedisMemberDetail,+ clampRedisMemberDetailSheetWidth,+ formatRedisCommandResult,+ formatRedisMemberDetail,+ formatRedisStringValue,+ getRedisMemberSelectionKey,+ highlightRedisJsonDetail,+ parseRedisJsonDetail,+ preferredRedisValueFormat,+ redisMemberCopyText,+ redisValueCopyText,+} from "../../apps/desktop/src/lib/redis/redisValuePresentation.ts";-test("formats JSON object strings for Redis member details", () => {+function blobFromText(value: string) {+ return {+ raw_base64: Buffer.from(value, "utf8").toString("base64"),+ encoding: "utf8" as const,+ };+}++test("keeps JSON-like strings as raw text in Redis member details", () => {const detail = formatRedisMemberDetail('{"id":1,"name":"Ada","tags":["dbx","redis"]}');- assert.equal(detail.format, "json");+ assert.equal(detail.format, "text");assert.equal(detail.rawText, '{"id":1,"name":"Ada","tags":["dbx","redis"]}');- assert.equal(detail.text, '{\n "id": 1,\n "name": "Ada",\n "tags": [\n "dbx",\n "redis"\n ]\n}');+ assert.equal(detail.text, '{"id":1,"name":"Ada","tags":["dbx","redis"]}');});test("keeps plain Redis member strings unchanged", () => {const detail = formatRedisMemberDetail("plain long member value");assert.equal(detail.format, "text");+ assert.equal(detail.rawLabel, "ASCII");assert.equal(detail.text, "plain long member value");+ assert.deepEqual(detail.availableFormats, ["utf8", "ascii", "binary", "hex", "base64"]);});test("formats JSON string values without changing plain strings", () => {@@ -22,18 +44,125 @@ test("formats JSON string values without changing plain strings", () => {assert.equal(formatRedisStringValue("plain redis value"), "plain redis value");});-test("parses Redis JSON details only for object and array containers", () => {+test("parses Redis JSON details for any valid JSON payload", () => {const objectDetail = parseRedisJsonDetail('{"id":1,"name":"Ada"}');assert.equal(objectDetail?.rawText, '{"id":1,"name":"Ada"}');assert.equal(objectDetail?.formattedText, '{\n "id": 1,\n "name": "Ada"\n}');assert.deepEqual(objectDetail?.value, { id: 1, name: "Ada" });assert.equal(parseRedisJsonDetail("[1,2]")?.formattedText, "[\n 1,\n 2\n]");- assert.equal(parseRedisJsonDetail('"plain json string"'), null);- assert.equal(parseRedisJsonDetail("123"), null);+ assert.equal(parseRedisJsonDetail('"plain json string"')?.formattedText, '"plain json string"');+ assert.equal(parseRedisJsonDetail("123")?.formattedText, "123");assert.equal(parseRedisJsonDetail("plain redis value"), null);});+test("string/blob formats stay text-oriented and binary-first where needed", () => {+ const jsonLikeTextDetail = formatRedisMemberDetail(blobFromText('{"name":"Ada"}'));+ assert.equal(jsonLikeTextDetail.rawLabel, "ASCII");+ assert.deepEqual(jsonLikeTextDetail.availableFormats, ["utf8", "ascii", "binary", "hex", "base64"]);+ assert.equal(jsonLikeTextDetail.defaultFormat, "utf8");+ assert.equal(jsonLikeTextDetail.utf8Text, '{"name":"Ada"}');+ assert.equal(jsonLikeTextDetail.asciiText, '{"name":"Ada"}');+ assert.equal(jsonLikeTextDetail.binaryText, "0111101100100010011011100110000101101101011001010010001000111010001000100100000101100100011000010010001001111101");+ assert.equal(jsonLikeTextDetail.rawText, '{"name":"Ada"}');++ const utf8Detail = formatRedisMemberDetail({+ raw_base64: Buffer.from("你好", "utf8").toString("base64"),+ encoding: "utf8" as const,+ });+ assert.equal(utf8Detail.rawLabel, "UTF-8");+ assert.deepEqual(utf8Detail.availableFormats, ["utf8", "ascii", "binary", "hex", "base64"]);+ assert.equal(utf8Detail.defaultFormat, "utf8");+ assert.equal(utf8Detail.utf8Text, "你好");+ assert.equal(utf8Detail.asciiText, "\\xe4\\xbd\\xa0\\xe5\\xa5\\xbd");+ assert.equal(utf8Detail.binaryText, "111001001011110110100000111001011010010110111101");+ assert.equal(utf8Detail.rawText, "你好");++ const binaryDetail = formatRedisMemberDetail({+ raw_base64: Buffer.from([0xac, 0xed, 0x00, 0x05]).toString("base64"),+ encoding: "binary" as const,+ });+ assert.equal(binaryDetail.rawLabel, "Binary");+ assert.deepEqual(binaryDetail.availableFormats, ["hex", "binary", "base64"]);+ assert.equal(binaryDetail.defaultFormat, "hex");+ assert.equal(binaryDetail.utf8Text, new TextDecoder("utf-8").decode(Uint8Array.from([0xac, 0xed, 0x00, 0x05])));+ assert.equal(binaryDetail.binaryText, "10101100111011010000000000000101");+});++test("detects Java-serialized payloads as a dedicated view", () => {+ const javaSerializedString = formatRedisMemberDetail({+ raw_base64: "rO0ABXQACHNvbWV0ZXh0",+ encoding: "binary" as const,+ });+ assert.deepEqual(javaSerializedString.availableFormats, ["javaserialize", "binary", "hex", "base64"]);+ assert.equal(javaSerializedString.defaultFormat, "javaserialize");+ assert.equal(javaSerializedString.javaSerialized?.formattedText, '"sometext"');++ const javaSerializedMap = formatRedisMemberDetail({+ raw_base64:+ "rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUHsMEzFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAACdAADYmFydAADYmF6dAADZm9vc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAHt4",+ encoding: "binary" as const,+ });+ assert.equal((javaSerializedMap.javaSerialized?.value as { $class?: string }).$class, "java.util.HashMap");+ assert.equal(+ ((javaSerializedMap.javaSerialized?.value as { obj?: { bar?: string } }).obj ?? {}).bar,+ "baz",+ );++ const plainText = formatRedisMemberDetail(blobFromText("Ada"));+ assert.equal(canRenderRedisValueFormat(plainText, "json"), false);+ assert.equal(canRenderRedisValueFormat(plainText, "javaserialize"), false);+ assert.equal(canRenderRedisValueFormat(plainText, "utf8"), true);++ assert.equal(canRenderRedisValueFormat(javaSerializedMap, "javaserialize"), true);+});++test("normalizes self-referential Java maps without recursing forever", () => {+ const detail = formatRedisMemberDetail({+ raw_base64: "rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAABdAAEc2VsZnEAfgABeA==",+ encoding: "binary" as const,+ });++ const normalized = detail.javaSerialized?.value as {+ $id?: string;+ map?: { $entries?: Array<{ key?: string; value?: { $ref?: string } }> };+ obj?: { self?: { $ref?: string } };+ };++ assert.equal(normalized.$id, "#1");+ assert.equal(normalized.map?.$entries?.[0]?.key, "self");+ assert.equal(normalized.map?.$entries?.[0]?.value?.$ref, "#1");+ assert.equal(normalized.obj?.self?.$ref, "#1");+});++test("only payload views opt into JSON text formatting", () => {+ const identityDetail = formatRedisMemberDetail(blobFromText('{"name":"Ada"}'));+ assert.deepEqual(identityDetail.availableFormats, ["utf8", "ascii", "binary", "hex", "base64"]);+ assert.equal(identityDetail.json, undefined);++ const payloadDetail = formatRedisMemberDetail(blobFromText('{"name":"Ada"}'), { allowJsonText: true });+ assert.equal(payloadDetail.rawLabel, "ASCII");+ assert.deepEqual(payloadDetail.availableFormats, ["utf8", "ascii", "binary", "json", "hex", "base64"]);+ assert.equal(payloadDetail.defaultFormat, "utf8");+ assert.equal(payloadDetail.json?.formattedText, '{\n "name": "Ada"\n}');+});++test("reuses only safe default formats for editable text values", () => {+ const textBlob = blobFromText("Ada");+ assert.equal(preferredRedisValueFormat(textBlob, "hex"), "utf8");+ assert.equal(preferredRedisValueFormat(textBlob, "base64"), "utf8");+ assert.equal(preferredRedisValueFormat(textBlob, "binary"), "utf8");++ const jsonTextBlob = blobFromText('{"name":"Ada"}');+ assert.equal(preferredRedisValueFormat(jsonTextBlob, "json", { allowJsonText: true }), "json");++ const binaryBlob = {+ raw_base64: Buffer.from([0xac, 0xed, 0x00, 0x05]).toString("base64"),+ encoding: "binary" as const,+ };+ assert.equal(preferredRedisValueFormat(binaryBlob, "base64"), "base64");+});+test("formats Redis command results with JSON strings expanded", () => {assert.equal(formatRedisCommandResult('{"balance":42,"unit":"USD"}'), '{\n "balance": 42,\n "unit": "USD"\n}');assert.equal(formatRedisCommandResult(["a", 2]), '[\n "a",\n 2\n]');@@ -46,10 +175,69 @@ test("formats non-string Redis member values as JSON", () => {assert.equal(detail.text, '{\n "field": "name",\n "value": "{\\"nested\\":true}"\n}');});-test("builds stable Redis member selection keys from title and formatted value", () => {+test("builds stable Redis member selection keys from title and raw value identity", () => {const key = getRedisMemberSelectionKey("#2", '{"id":240,"kind":"json"}');- assert.equal(key, '#2\n{\n "id": 240,\n "kind": "json"\n}');+ assert.equal(key, '#2\n{"id":240,"kind":"json"}');+});++test("lets selection keys disambiguate duplicate stream fields", () => {+ const first = getRedisMemberSelectionKey("event", "login", "stream:1714470000000-0:0");+ const second = getRedisMemberSelectionKey("event", "login", "stream:1714470000000-0:1");++ assert.notEqual(first, second);+});++test("copies binary members as escaped raw bytes instead of bitstrings", () => {+ const binaryBlob = {+ raw_base64: Buffer.from([0xac, 0xed, 0x00, 0x05]).toString("base64"),+ encoding: "binary" as const,+ };++ assert.equal(redisMemberCopyText(binaryBlob), "\\xac\\xed\\x00\\x05");+});++test("copies collection values as readable content instead of blob transport objects", () => {+ const value = {+ key_display: "users",+ key_raw: "users",+ ttl: -1,+ redis_type: "hash",+ data: {+ kind: "hash" as const,+ items: [{ field: blobFromText("name"), value: blobFromText("Ada") }],+ total: 1,+ },+ };++ assert.equal(redisValueCopyText(value), '[\n {\n "field": "name",\n "value": "Ada"\n }\n]');+});++test("copies stream entries without collapsing repeated field names", () => {+ const value = {+ key_display: "events",+ key_raw: "events",+ ttl: -1,+ redis_type: "stream",+ data: {+ kind: "stream" as const,+ entries: [+ {+ id: "1728123456789-0",+ fields: [+ { field: "event", value: "login" },+ { field: "event", value: "logout" },+ { field: "user_id", value: "42" },+ ],+ },+ ],+ },+ };++ assert.equal(+ redisValueCopyText(value),+ '[\n {\n "id": "1728123456789-0",\n "fields": [\n {\n "field": "event",\n "value": "login"\n },\n {\n "field": "event",\n "value": "logout"\n },\n {\n "field": "user_id",\n "value": "42"\n }\n ]\n }\n]',+ );});test("highlights formatted Redis JSON detail safely", () => {diff --git a/src-tauri/src/commands/redis_cmd.rs b/src-tauri/src/commands/redis_cmd.rsindex 998495b41c..b3d480b294 100644--- a/src-tauri/src/commands/redis_cmd.rs+++ b/src-tauri/src/commands/redis_cmd.rs@@ -3,7 +3,7 @@ use tauri::State;use crate::commands::connection::{ensure_connection_writable, AppState};use dbx_core::db::redis_driver::{- RedisCommandResult, RedisCommandSafety, RedisDatabaseInfo, RedisScanResult, RedisValue,+ RedisCollectionPage, RedisCommandResult, RedisCommandSafety, RedisDatabaseInfo, RedisScanResult, RedisValue,};#[tauri::command]@@ -325,7 +325,7 @@ pub async fn redis_load_more(cursor: u64,count: usize,filter: Option<String>,-) -> Result<RedisValue, String> {+) -> Result<RedisCollectionPage, String> {dbx_core::redis_ops::redis_load_more_in_db_core(&state,&connection_id,