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 () => {
Tiny RDM
- - {{ get(tabStore.currentTab, 'name') }} + - {{ tabStore.currentTabName }} @@ -174,13 +174,15 @@ onMounted(async () => { @update:size="handleResize"> diff --git a/frontend/src/components/common/RedisTypeSelector.vue b/frontend/src/components/common/RedisTypeSelector.vue index c6abe5d..718cf9a 100644 --- a/frontend/src/components/common/RedisTypeSelector.vue +++ b/frontend/src/components/common/RedisTypeSelector.vue @@ -3,6 +3,7 @@ import { computed, h } from 'vue' import { useThemeVars } from 'naive-ui' import { types, typesBgColor, typesColor } from '@/consts/support_redis_type.js' import { get, map, toUpper } from 'lodash' +import RedisTypeTag from '@/components/common/RedisTypeTag.vue' const props = defineProps({ value: { @@ -23,15 +24,24 @@ const options = computed(() => { const themeVars = useThemeVars() const renderIcon = (option) => { - if (option.key === props.value) { - const backgroundColor = get(typesColor, option.key, themeVars.value.textColor3) - return h('div', { style: { borderRadius: '999px', width: '10px', height: '10px', backgroundColor } }, '') - } + return h(RedisTypeTag, { + type: option.key, + short: true, + size: 'small', + inverse: option.key === props.value, + }) } const renderLabel = (option) => { - const color = get(typesColor, option.key, '') - return h('div', { style: { color, fontWeight: '450' } }, option.label) + return h( + 'div', + { + style: { + fontWeight: option.key === props.value ? 'bold' : 'normal', + }, + }, + option.label, + ) } const fontColor = computed(() => { diff --git a/frontend/src/components/common/RedisTypeTag.vue b/frontend/src/components/common/RedisTypeTag.vue index eb9573d..1862c56 100644 --- a/frontend/src/components/common/RedisTypeTag.vue +++ b/frontend/src/components/common/RedisTypeTag.vue @@ -1,45 +1,69 @@