Skip to content

Support editing Redis hash fields - #7140

Merged
t8y2 merged 5 commits into
t8y2:mainfrom
onenewcode:fix/redis-hash-field-edit
Aug 26, 2026
Merged

Support editing Redis hash fields#7140
t8y2 merged 5 commits into
t8y2:mainfrom
onenewcode:fix/redis-hash-field-edit

Conversation

@onenewcode

@onenewcode onenewcode commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

变更说明

为 Redis Hash 成员详情增加 field 编辑能力,并按 review 要求改为安全的原子后端更新

  1. 原子 rename / value 更新
    前端不再用 HSET 新 field 再 HDEL 旧 field 的两段请求。
    改为单一后端操作 redisHashFieldUpdate(Direct / Cluster 同一路径),在服务端用 一条 EVAL 完成:

    • 源 field 存在性检查
    • 目标名冲突拒绝(不覆盖已有 field)
    • 写入新值 / 新 field
    • 删除旧 field(rename 时)
    • 在支持 hash-field expiry 的 Redis 上用 HTTL/HEXPIRE 保留原 field TTL
      脚本内对后续失败做回滚/清理,避免留下双 field 或静默丢 TTL;权限不足时明确报错,不回退到非原子路径。
  2. 不规范化 field 身份
    保存时不再对 field 名做 .trim()。例如已有 " user " 只改 value 时仍保持 " user "。空 field 名(length === 0)仍拒绝。

  3. field 草稿进入 dirty / unsaved 保护
    单独保留 memberFieldDraftBaseline,field-only 编辑参与 memberFieldChanged / memberValueChanged / hasRetainedMemberDraft / hasUnsavedRedisDraft。关闭再打开详情不会静默丢掉未保存的 field 改名。

变更类型

  • 新功能
  • Bug 修复(相对初版 HSET+HDEL 路径的安全修复)
  • 性能优化
  • 代码重构
  • 文档更新
  • CI / 构建

涉及前端

  • 本 PR 涉及前端改动,已附截图/录屏(见下方)

主要改动面

  • crates/dbx-core: hash_field_update Lua EVAL + Direct/Cluster ops
  • dbx-web / src-tauri: /redis/hash-field-updateredis_hash_field_update 命令
  • apps/desktop: RedisValueViewerapi.redisHashFieldUpdate;field draft baseline;无 trim
  • 测试:driver 单元测试(碰撞 / TTL 脚本 / 缺失源 / value-only / 原子失败 / 串行 loser)+ Vue AST 接线测试(无 trim、draft dirty、redisHashFieldUpdate

关联 Issue

Close #7129

@github-actions github-actions Bot added area/desktop Desktop application or Tauri shell db/redis Database: Redis ui-change Changes user-visible interface, text, or visual assets labels Aug 25, 2026

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes: the current Redis hash field rename path is not safe enough to merge.

  1. apps/desktop/src/components/redis/RedisValueViewer.vue:2043-2044 implements rename as two independent requests: HSET newField followed by HDEL oldField. This overwrites an existing destination field, permits concurrent writes between the two commands, and leaves duplicate fields when the delete fails.

    Please move rename into one backend operation that atomically rejects destination collisions and updates/deletes the field through the same Direct/Cluster path. Preserve the original field TTL where supported, and add collision, TTL, partial-failure, and concurrency regressions.

  2. RedisValueViewer.vue:2031 trims the edited field before writing it. An existing field such as " user " is silently renamed to "user" even when only its value changes. Preserve the field bytes exactly instead of normalizing its identity.

  3. Field-only edits are not included in the dirty/draft state, so closing and reopening the detail view silently discards the edited field name. Include field changes in draft retention, refresh protection, and save-state tests.

Replace the client-side HSET+HDEL hash field rename with one backend
EVAL that rejects destination collisions, preserves field TTL when
supported, and rolls back partial writes. Stop trimming field identity
on save, and keep field-name drafts in dirty/unsaved retention so
close/reopen does not drop renames.
@github-actions github-actions Bot added area/core Shared DBX core runtime area/web Web backend or web API labels Aug 26, 2026
@onenewcode
onenewcode requested a review from t8y2 August 26, 2026 01:35

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a small follow-up at 7e06a7c.

The new field input uses t('redis.field'), but the redis namespace had no bare field key (only mongo does), so the placeholder and aria-label rendered the literal "redis.field". Added field to the redis sections of en.ts / zh-CN.ts / zh-TW.ts next to fieldRequired; other locales will be picked up by the i18n autofill workflow.

Checks run: vue-tsc --noEmit clean, oxlint zero warnings on the three locale files.

@github-actions

Copy link
Copy Markdown
Contributor

🌐 I18n autofill completed

✅ Added translations for 1 new zh-CN i18n key.

Locale Added entries
es 1
it 1
ja 1
pt-BR 1

@t8y2
t8y2 merged commit 0f9d32e into t8y2:main Aug 26, 2026
13 checks passed
@t8y2

t8y2 commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 0f9d32e, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Shared DBX core runtime area/desktop Desktop application or Tauri shell area/web Web backend or web API db/redis Database: Redis ui-change Changes user-visible interface, text, or visual assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 建议redis hash表, 可以修改field值

2 participants