From af6b4257f9538e2ec183c0ed26d8c38ef745bd94 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:43:25 +0800 Subject: [PATCH] feat: add type display in key browser --- backend/services/browser_service.go | 29 ++++ backend/types/js_resp.go | 6 +- frontend/src/AppContent.vue | 10 +- .../components/common/RedisTypeSelector.vue | 22 ++- .../src/components/common/RedisTypeTag.vue | 44 ++++-- .../src/components/dialogs/NewKeyDialog.vue | 2 +- .../src/components/sidebar/BrowserPane.vue | 137 ++++++++++-------- .../src/components/sidebar/BrowserTree.vue | 32 +++- frontend/src/consts/support_redis_type.js | 9 ++ frontend/src/stores/browser.js | 28 ++++ frontend/src/stores/tab.js | 4 + frontend/src/styles/style.scss | 11 ++ 12 files changed, 239 insertions(+), 95 deletions(-) diff --git a/backend/services/browser_service.go b/backend/services/browser_service.go index 907cbd6..683b7fa 100644 --- a/backend/services/browser_service.go +++ b/backend/services/browser_service.go @@ -516,6 +516,35 @@ func (b *browserService) LoadAllKeys(connName string, db int, match, keyType str return } +func (b *browserService) GetKeyType(param types.KeySummaryParam) (resp types.JSResp) { + item, err := b.getRedisClient(param.Server, param.DB) + if err != nil { + resp.Msg = err.Error() + return + } + + client, ctx := item.client, item.ctx + key := strutil.DecodeRedisKey(param.Key) + var keyType string + keyType, err = client.Type(ctx, key).Result() + if err != nil { + resp.Msg = err.Error() + return + } + + if keyType == "none" { + resp.Msg = "key not exists" + return + } + + var data types.KeySummary + data.Type = strings.ToLower(keyType) + + resp.Success = true + resp.Data = data + return +} + // GetKeySummary get key summary info func (b *browserService) GetKeySummary(param types.KeySummaryParam) (resp types.JSResp) { item, err := b.getRedisClient(param.Server, param.DB) diff --git a/backend/types/js_resp.go b/backend/types/js_resp.go index ceb4e8a..3e5ef09 100644 --- a/backend/types/js_resp.go +++ b/backend/types/js_resp.go @@ -14,9 +14,9 @@ type KeySummaryParam struct { type KeySummary struct { Type string `json:"type"` - TTL int64 `json:"ttl"` - Size int64 `json:"size"` - Length int64 `json:"length"` + TTL int64 `json:"ttl,omitempty"` + Size int64 `json:"size,omitempty"` + Length int64 `json:"length,omitempty"` } type KeyDetailParam struct { diff --git a/frontend/src/AppContent.vue b/frontend/src/AppContent.vue index d3d6093..1f7faf9 100644 --- a/frontend/src/AppContent.vue +++ b/frontend/src/AppContent.vue @@ -2,7 +2,7 @@ import ContentPane from './components/content/ContentPane.vue' import BrowserPane from './components/sidebar/BrowserPane.vue' import { computed, onMounted, reactive, ref, watch } from 'vue' -import { debounce, get } from 'lodash' +import { debounce } from 'lodash' import { useThemeVars } from 'naive-ui' import Ribbon from './components/sidebar/Ribbon.vue' import ConnectionPane from './components/sidebar/ConnectionPane.vue' @@ -139,7 +139,7 @@ onMounted(async () => {