Skip to content

feat(redis): add key statistics tracking for database browser#269

Merged
t8y2 merged 1 commit into
t8y2:mainfrom
Abeautifulsnow:feat/redis-key-counts
May 14, 2026
Merged

feat(redis): add key statistics tracking for database browser#269
t8y2 merged 1 commit into
t8y2:mainfrom
Abeautifulsnow:feat/redis-key-counts

Conversation

@Abeautifulsnow
Copy link
Copy Markdown
Contributor

Background Description

Add key statistics functionality to the Redis database browser to display the number of loaded keys / total number of keys,
and update it in real-time during dynamic loading, deletion, and flushing.

Modifications

  • Add a RedisDatabaseInfo struct (db + keys) to replace the original Vec<u32>
  • list_databases returns the key count for each db (parsing INFO keyspace)
  • scan_keys_page adds a DBSIZE call to obtain total_keys
  • The frontend TreeNode adds loadedKeyCount / totalKeyCount fields
  • The tree node label dynamically displays the db0 (loaded/total) format
  • Add updateRedisDbKeyStats to update statistics during loading/deletion/flushing

## 背景说明
为 Redis 数据库浏览器增加键统计功能,显示已加载 key 数/总 key 数,
并在动态加载、删除、清空时实时更新。

## 修改内容
- 新增 \RedisDatabaseInfo\ 结构体(db + keys),替代原来的 \Vec<u32>\
- \list_databases\ 返回每个 db 的 key 数量(解析 INFO keyspace)
- \scan_keys_page\ 增加 DBSIZE 调用获取 total_keys
- 前端 TreeNode 增加 loadedKeyCount/totalKeyCount 字段
- 树节点标签动态显示 \db0 (loaded/total)\ 格式
- 新增 \updateRedisDbKeyStats\ 在加载/删除/清空时更新统计

## 测试
- 建议补充 list_keyspace_databases 解析异常输入的单测
- 建议补充 redisDbLabel 边界值测试
Copy link
Copy Markdown
Owner

@t8y2 t8y2 left a comment

Choose a reason for hiding this comment

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

✅ Well Done

  • Clean architecture: Backend returns RedisDatabaseInfo { db, keys } from INFO keyspace parsing, and total_keys from DBSIZE — both O(1) Redis commands, so no performance concern.
  • Smart delta-based updates: updateRedisDbKeyStats supports loaded, total, and totalDelta modes, with Math.max(0, ...) to prevent negative counts. This elegantly handles delete (single and bulk) and flush scenarios without re-querying Redis.
  • Correct search mode handling: When in search mode, loaded is passed as undefined so loadedKeyCount isn't corrupted by filtered results.
  • Type consistency across the stack: RedisDatabaseInfo is defined in Rust, mirrored in TypeScript (tauri.ts), and properly re-exported through the API layer.
  • redisDbLabel helper is clean and handles the totalKeyCount == null edge case gracefully.
  • Backward compatible: loadedKeyCount and totalKeyCount are optional on TreeNode, so existing non-Redis tree nodes are unaffected.

LGTM! 🎉

@t8y2 t8y2 merged commit 919c3d5 into t8y2:main May 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants