feat(redis): add key statistics tracking for database browser#269
Merged
Conversation
## 背景说明 为 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 边界值测试
t8y2
approved these changes
May 14, 2026
Owner
t8y2
left a comment
There was a problem hiding this comment.
✅ Well Done
- Clean architecture: Backend returns
RedisDatabaseInfo { db, keys }fromINFO keyspaceparsing, andtotal_keysfromDBSIZE— both O(1) Redis commands, so no performance concern. - Smart delta-based updates:
updateRedisDbKeyStatssupportsloaded,total, andtotalDeltamodes, withMath.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,
loadedis passed asundefinedsoloadedKeyCountisn't corrupted by filtered results. - Type consistency across the stack:
RedisDatabaseInfois defined in Rust, mirrored in TypeScript (tauri.ts), and properly re-exported through the API layer. redisDbLabelhelper is clean and handles thetotalKeyCount == nulledge case gracefully.- Backward compatible:
loadedKeyCountandtotalKeyCountare optional onTreeNode, so existing non-Redis tree nodes are unaffected.
LGTM! 🎉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
RedisDatabaseInfostruct (db + keys) to replace the originalVec<u32>list_databasesreturns the key count for each db (parsingINFO keyspace)scan_keys_pageadds aDBSIZEcall to obtaintotal_keysTreeNodeaddsloadedKeyCount/totalKeyCountfieldsdb0 (loaded/total)formatupdateRedisDbKeyStatsto update statistics during loading/deletion/flushing