perf: refresh key summary after crud value content

This commit is contained in:
Lykin 2023-12-14 16:35:37 +08:00
parent 566a7e212f
commit d31da4a055
13 changed files with 272 additions and 141 deletions

View File

@ -562,47 +562,59 @@ func (b *browserService) GetKeySummary(param types.KeySummaryParam) (resp types.
client, ctx := item.client, item.ctx client, ctx := item.client, item.ctx
key := strutil.DecodeRedisKey(param.Key) key := strutil.DecodeRedisKey(param.Key)
var keyType string
var dur time.Duration pipe := client.Pipeline()
keyType, err = client.Type(ctx, key).Result() typeVal := pipe.Type(ctx, key)
ttlVal := pipe.TTL(ctx, key)
sizeVal := pipe.MemoryUsage(ctx, key, 0)
_, err = pipe.Exec(ctx)
if err != nil { if err != nil {
resp.Msg = err.Error() resp.Msg = err.Error()
return return
} }
if keyType == "none" { if typeVal.Err() != nil {
resp.Msg = typeVal.Err().Error()
return
}
data := types.KeySummary{
Type: strings.ToLower(typeVal.Val()),
Size: sizeVal.Val(),
}
if data.Type == "none" {
resp.Msg = "key not exists" resp.Msg = "key not exists"
return return
} }
var data types.KeySummary if ttlVal.Err() != nil {
data.Type = strings.ToLower(keyType)
if dur, err = client.TTL(ctx, key).Result(); err != nil {
data.TTL = -1 data.TTL = -1
} else { } else {
if dur < 0 { if ttlVal.Val() < 0 {
data.TTL = -1 data.TTL = -1
} else { } else {
data.TTL = int64(dur.Seconds()) data.TTL = int64(ttlVal.Val().Seconds())
} }
} }
data.Size, _ = client.MemoryUsage(ctx, key, 0).Result()
switch data.Type { switch data.Type {
case "string": case "string":
data.Length, _ = client.StrLen(ctx, key).Result() data.Length, err = client.StrLen(ctx, key).Result()
case "list": case "list":
data.Length, _ = client.LLen(ctx, key).Result() data.Length, err = client.LLen(ctx, key).Result()
case "hash": case "hash":
data.Length, _ = client.HLen(ctx, key).Result() data.Length, err = client.HLen(ctx, key).Result()
case "set": case "set":
data.Length, _ = client.SCard(ctx, key).Result() data.Length, err = client.SCard(ctx, key).Result()
case "zset": case "zset":
data.Length, _ = client.ZCard(ctx, key).Result() data.Length, err = client.ZCard(ctx, key).Result()
case "stream": case "stream":
data.Length, _ = client.XLen(ctx, key).Result() data.Length, err = client.XLen(ctx, key).Result()
default: default:
resp.Msg = "unknown key type" err = errors.New("unknown key type")
}
if err != nil {
resp.Msg = err.Error()
return return
} }

View File

@ -205,12 +205,13 @@ const actionColumn = {
onEdit: () => startEdit(index + 1, row.k, row.v), onEdit: () => startEdit(index + 1, row.k, row.v),
onDelete: async () => { onDelete: async () => {
try { try {
const { removed, success, msg } = await browserStore.removeHashField( const { removed, success, msg } = await browserStore.removeHashField({
props.name, server: props.name,
props.db, db: props.db,
keyName.value, key: keyName.value,
row.k, field: row.k,
) reload: false,
})
if (success) { if (success) {
props.value.splice(index, 1) props.value.splice(index, 1)
$message.success(i18n.t('dialogue.delete_key_succ', { key: row.k })) $message.success(i18n.t('dialogue.delete_key_succ', { key: row.k }))

View File

@ -183,14 +183,13 @@ const actionColumn = {
}, },
onDelete: async () => { onDelete: async () => {
try { try {
const { success, msg } = await browserStore.removeListItem( const { success, msg } = await browserStore.removeListItem({
props.name, server: props.name,
props.db, db: props.db,
keyName.value, key: keyName.value,
index, index,
) })
if (success) { if (success) {
props.value.splice(index, 1)
$message.success(i18n.t('dialogue.delete_key_succ', { key: `#${index + 1}` })) $message.success(i18n.t('dialogue.delete_key_succ', { key: `#${index + 1}` }))
} else { } else {
$message.error(msg) $message.error(msg)

View File

@ -180,14 +180,13 @@ const actionColumn = {
}, },
onDelete: async () => { onDelete: async () => {
try { try {
const { success, msg } = await browserStore.removeSetItem( const { success, msg } = await browserStore.removeSetItem({
props.name, server: props.name,
props.db, db: props.db,
keyName.value, key: keyName.value,
row.v, value: row.v,
) })
if (success) { if (success) {
// props.value.splice(index, 1)
$message.success(i18n.t('dialogue.delete_key_succ', { key: row.v })) $message.success(i18n.t('dialogue.delete_key_succ', { key: row.v }))
} else { } else {
$message.error(msg) $message.error(msg)

View File

@ -120,12 +120,12 @@ const actionColumn = {
}, },
onDelete: async () => { onDelete: async () => {
try { try {
const { success, msg } = await browserStore.removeStreamValues( const { success, msg } = await browserStore.removeStreamValues({
props.name, server: props.name,
props.db, db: props.db,
keyName.value, key: keyName.value,
row.id, ids: row.id,
) })
if (success) { if (success) {
$message.success(i18n.t('dialogue.delete_key_succ', { key: row.id })) $message.success(i18n.t('dialogue.delete_key_succ', { key: row.id }))
} else { } else {

View File

@ -145,7 +145,6 @@ const onSave = async () => {
decode: viewAs.decode, decode: viewAs.decode,
}) })
if (success) { if (success) {
// await browserStore.loadKeyDetail({ server: props.name, db: props.db, key: keyName.value })
$message.success(i18n.t('interface.save_value_succ')) $message.success(i18n.t('interface.save_value_succ'))
} else { } else {
$message.error(msg) $message.error(msg)

View File

@ -227,14 +227,13 @@ const actionColumn = {
onEdit: () => startEdit(index + 1, row.s, row.v), onEdit: () => startEdit(index + 1, row.s, row.v),
onDelete: async () => { onDelete: async () => {
try { try {
const { success, msg } = await browserStore.removeZSetItem( const { success, msg } = await browserStore.removeZSetItem({
props.name, server: props.name,
props.db, db: props.db,
keyName.value, key: keyName.value,
row.v, value: row.v,
) })
if (success) { if (success) {
// props.value.splice(index, 1)
$message.success(i18n.t('dialogue.delete_key_succ', { key: row.v })) $message.success(i18n.t('dialogue.delete_key_succ', { key: row.v }))
} else { } else {
$message.error(msg) $message.error(msg)

View File

@ -9,7 +9,7 @@ import AddListValue from '@/components/new_value/AddListValue.vue'
import AddHashValue from '@/components/new_value/AddHashValue.vue' import AddHashValue from '@/components/new_value/AddHashValue.vue'
import AddZSetValue from '@/components/new_value/AddZSetValue.vue' import AddZSetValue from '@/components/new_value/AddZSetValue.vue'
import NewStreamValue from '@/components/new_value/NewStreamValue.vue' import NewStreamValue from '@/components/new_value/NewStreamValue.vue'
import { isEmpty, size, slice } from 'lodash' import { get, isEmpty, size, slice } from 'lodash'
import useBrowserStore from 'stores/browser.js' import useBrowserStore from 'stores/browser.js'
import useTabStore from 'stores/tab.js' import useTabStore from 'stores/tab.js'
@ -22,7 +22,7 @@ const newForm = reactive({
type: '', type: '',
opType: 0, opType: 0,
value: null, value: null,
reload: true, reload: false,
}) })
const addValueComponent = { const addValueComponent = {
@ -89,88 +89,102 @@ const onAdd = async () => {
value = defaultValue[type] value = defaultValue[type]
} }
const keyName = isEmpty(keyCode) ? key : keyCode const keyName = isEmpty(keyCode) ? key : keyCode
let updated = false let success = false
let msg = ''
switch (type) { switch (type) {
case types.LIST: case types.LIST:
{ {
let data let data
if (newForm.opType === 1) { if (newForm.opType === 1) {
data = await browserStore.prependListItem({ server, db, key: keyName, values: value }) data = await browserStore.prependListItem({
server,
db,
key: keyName,
values: value,
reload: newForm.reload,
})
} else { } else {
data = await browserStore.appendListItem({ server, db, key: keyName, values: value }) data = await browserStore.appendListItem({
} server,
const { success, msg } = data db,
if (success) { key: keyName,
updated = true values: value,
$message.success(i18n.t('dialogue.handle_succ')) reload: newForm.reload,
} else { })
$message.error(msg)
} }
success = get(data, 'success')
msg = get(data, 'msg')
} }
break break
case types.HASH: case types.HASH:
{ {
const { success, msg } = await browserStore.addHashField(server, db, keyName, newForm.opType, value) const data = await browserStore.addHashField({
if (success) { server,
updated = true db,
$message.success(i18n.t('dialogue.handle_succ')) key: keyName,
} else { action: newForm.opType,
$message.error(msg) fieldItems: value,
} reload: newForm.reload,
})
success = get(data, 'success')
msg = get(data, 'msg')
} }
break break
case types.SET: case types.SET:
{ {
const { success, msg } = await browserStore.addSetItem(server, db, keyName, value) const data = await browserStore.addSetItem({
if (success) { server,
updated = true db,
$message.success(i18n.t('dialogue.handle_succ')) key: keyName,
} else { value,
$message.error(msg) reload: newForm.reload,
} })
success = get(data, 'success')
msg = get(data, 'msg')
} }
break break
case types.ZSET: case types.ZSET:
{ {
const { success, msg } = await browserStore.addZSetItem(server, db, keyName, newForm.opType, value) const data = await browserStore.addZSetItem({
if (success) { server,
updated = true db,
$message.success(i18n.t('dialogue.handle_succ')) key: keyName,
} else { action: newForm.opType,
$message.error(msg) vs: value,
} reload: newForm.reload,
})
success = get(data, 'success')
msg = get(data, 'msg')
} }
break break
case types.STREAM: case types.STREAM:
{ {
if (size(value) > 2) { if (size(value) > 2) {
const { success, msg } = await browserStore.addStreamValue( const data = await browserStore.addStreamValue({
server, server,
db, db,
keyName, key: keyName,
value[0], id: value[0],
slice(value, 1), values: slice(value, 1),
) reload: newForm.reload,
if (success) { })
updated = true success = get(data, 'success')
$message.success(i18n.t('dialogue.handle_succ')) msg = get(data, 'msg')
} else {
$message.error(msg)
}
} }
} }
break break
} }
if (updated) { if (success) {
if (newForm.reload) { $message.success(i18n.t('dialogue.handle_succ'))
browserStore.reloadKey({ server, db, key: keyName }) } else if (!isEmpty(msg)) {
} $message.error(msg)
} }
dialogStore.closeAddFieldsDialog() dialogStore.closeAddFieldsDialog()
} catch (e) { } catch (e) {
$message.error(e.message) $message.error(e.message)

View File

@ -46,7 +46,7 @@ const options = computed(() => {
label: t, label: t,
})) }))
}) })
const addValueComponent = { const newValueComponent = {
[types.STRING]: NewStringValue, [types.STRING]: NewStringValue,
[types.HASH]: NewHashValue, [types.HASH]: NewHashValue,
[types.LIST]: NewListValue, [types.LIST]: NewListValue,
@ -136,7 +136,7 @@ const onAdd = async () => {
if (success) { if (success) {
// select current key // select current key
tabStore.setSelectedKeys(server, nodeKey) tabStore.setSelectedKeys(server, nodeKey)
browserStore.loadKeySummary({ server, db, key }) browserStore.loadKeySummary({ server, db, key, clearValue: true })
} else if (!isEmpty(msg)) { } else if (!isEmpty(msg)) {
$message.error(msg) $message.error(msg)
} }
@ -206,7 +206,7 @@ const onClose = () => {
</n-button> </n-button>
</n-input-group> </n-input-group>
</n-form-item> </n-form-item>
<component :is="addValueComponent[newForm.type]" ref="subFormRef" v-model:value="newForm.value" /> <component :is="newValueComponent[newForm.type]" ref="subFormRef" v-model:value="newForm.value" />
<!-- TODO: Add import from txt file option --> <!-- TODO: Add import from txt file option -->
</n-form> </n-form>
</n-scrollbar> </n-scrollbar>

View File

@ -166,7 +166,7 @@ const handleSelectDB = async (db) => {
await browserStore.openDatabase(props.server, db) await browserStore.openDatabase(props.server, db)
await nextTick() await nextTick()
await connectionStore.saveLastDB(props.server, db) await connectionStore.saveLastDB(props.server, db)
tabStore.upsertTab({ server: props.server, db }) tabStore.upsertTab({ server: props.server, db, clearValue: true })
// browserTreeRef.value?.resetExpandKey(props.server, db) // browserTreeRef.value?.resetExpandKey(props.server, db)
fullyLoaded.value = await browserStore.loadMoreKeys(props.server, db) fullyLoaded.value = await browserStore.loadMoreKeys(props.server, db)
browserTreeRef.value?.refreshTree() browserTreeRef.value?.refreshTree()

View File

@ -288,6 +288,7 @@ const onUpdateSelectedKeys = (keys, options) => {
server: props.server, server: props.server,
db, db,
key: redisKey, key: redisKey,
clearValue: true,
}) })
} }
return return

View File

@ -413,9 +413,10 @@ const useBrowserStore = defineStore('browser', {
* @param {string} server * @param {string} server
* @param {number} db * @param {number} db
* @param {string|number[]} [key] null or blank indicate that update tab to display normal content (blank content or server status) * @param {string|number[]} [key] null or blank indicate that update tab to display normal content (blank content or server status)
* @param {boolean} [clearValue]
* @return {Promise<void>} * @return {Promise<void>}
*/ */
async loadKeySummary({ server, db, key }) { async loadKeySummary({ server, db, key, clearValue }) {
try { try {
const tab = useTabStore() const tab = useTabStore()
if (!isEmpty(key)) { if (!isEmpty(key)) {
@ -438,6 +439,7 @@ const useBrowserStore = defineStore('browser', {
key: k, key: k,
size, size,
length, length,
clearValue,
}) })
return return
} else { } else {
@ -458,9 +460,9 @@ const useBrowserStore = defineStore('browser', {
ttl: -1, ttl: -1,
key: null, key: null,
keyCode: null, keyCode: null,
value: null,
size: 0, size: 0,
length: 0, length: 0,
clearValue,
}) })
} catch (e) { } catch (e) {
$message.error('') $message.error('')
@ -511,7 +513,7 @@ const useBrowserStore = defineStore('browser', {
const tab = useTabStore() const tab = useTabStore()
try { try {
tab.updateLoading({ server, db, loading: true }) tab.updateLoading({ server, db, loading: true })
await this.loadKeySummary({ server, db, key }) await this.loadKeySummary({ server, db, key, clearValue: true })
await this.loadKeyDetail({ server, db, key, decode, format, matchPattern, reset: true }) await this.loadKeyDetail({ server, db, key, decode, format, matchPattern, reset: true })
} finally { } finally {
tab.updateLoading({ server, db, loading: false }) tab.updateLoading({ server, db, loading: false })
@ -1065,6 +1067,8 @@ const useBrowserStore = defineStore('browser', {
} }
const tab = useTabStore() const tab = useTabStore()
tab.updateValue({ server, db, key, value }) tab.updateValue({ server, db, key, value })
this.loadKeySummary({ server, db, key })
return { return {
success, success,
nodeKey: `${server}/db${db}#${ConnectionType.RedisValue}/${key}`, nodeKey: `${server}/db${db}#${ConnectionType.RedisValue}/${key}`,
@ -1096,6 +1100,7 @@ const useBrowserStore = defineStore('browser', {
* @param {formatTypes} [retFormat] * @param {formatTypes} [retFormat]
* @param {boolean} [refresh] * @param {boolean} [refresh]
* @param {number} [index] index for retrieve affect entries quickly * @param {number} [index] index for retrieve affect entries quickly
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean, [updated]: {}}>} * @returns {Promise<{[msg]: string, success: boolean, [updated]: {}}>}
*/ */
async setHash({ async setHash({
@ -1110,6 +1115,7 @@ const useBrowserStore = defineStore('browser', {
retDecode, retDecode,
retFormat, retFormat,
index, index,
reload,
}) { }) {
try { try {
const { data, success, msg } = await SetHashValue({ const { data, success, msg } = await SetHashValue({
@ -1150,6 +1156,12 @@ const useBrowserStore = defineStore('browser', {
index: [index], index: [index],
}) })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success, updated } return { success, updated }
} else { } else {
return { success, msg } return { success, msg }
@ -1166,9 +1178,10 @@ const useBrowserStore = defineStore('browser', {
* @param {string|number[]} key * @param {string|number[]} key
* @param {number }action 0:ignore duplicated fields 1:overwrite duplicated fields * @param {number }action 0:ignore duplicated fields 1:overwrite duplicated fields
* @param {string[]} fieldItems field1, value1, filed2, value2... * @param {string[]} fieldItems field1, value1, filed2, value2...
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean, [updated]: [], [added]: []}>} * @returns {Promise<{[msg]: string, success: boolean, [updated]: [], [added]: []}>}
*/ */
async addHashField(server, db, key, action, fieldItems) { async addHashField({ server, db, key, action, fieldItems, reload }) {
try { try {
const { data, success, msg } = await AddHashField(server, db, key, action, fieldItems) const { data, success, msg } = await AddHashField(server, db, key, action, fieldItems)
if (success) { if (success) {
@ -1180,6 +1193,12 @@ const useBrowserStore = defineStore('browser', {
if (!isEmpty(added)) { if (!isEmpty(added)) {
tab.insertValueEntries({ server, db, key, type: 'hash', entries: added }) tab.insertValueEntries({ server, db, key, type: 'hash', entries: added })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success, updated, added } return { success, updated, added }
} else { } else {
return { success: false, msg } return { success: false, msg }
@ -1195,9 +1214,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string} field * @param {string} field
* @param {boolean} reload
* @returns {Promise<{[msg]: {}, success: boolean, [removed]: string[]}>} * @returns {Promise<{[msg]: {}, success: boolean, [removed]: string[]}>}
*/ */
async removeHashField(server, db, key, field) { async removeHashField({ server, db, key, field, reload }) {
try { try {
const { data, success, msg } = await SetHashValue({ server, db, key, field, newField: '' }) const { data, success, msg } = await SetHashValue({ server, db, key, field, newField: '' })
if (success) { if (success) {
@ -1206,6 +1226,12 @@ const useBrowserStore = defineStore('browser', {
// const tab = useTabStore() // const tab = useTabStore()
// tab.removeValueEntries({ server, db, key, type: 'hash', entries: removed }) // tab.removeValueEntries({ server, db, key, type: 'hash', entries: removed })
// } // }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success, removed } return { success, removed }
} else { } else {
return { success, msg } return { success, msg }
@ -1215,32 +1241,16 @@ const useBrowserStore = defineStore('browser', {
} }
}, },
/**
* insert list item
* @param {string} connName
* @param {number} db
* @param {string|number[]} key
* @param {int} action 0: push to head, 1: push to tail
* @param {string[]}values
* @returns {Promise<*|{msg, success: boolean}>}
*/
async addListItem(connName, db, key, action, values) {
try {
return AddListItem(connName, db, key, action, values)
} catch (e) {
return { success: false, msg: e.message }
}
},
/** /**
* prepend item to head of list * prepend item to head of list
* @param {string} server * @param {string} server
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string[]} values * @param {string[]} values
* @param {boolean} reload
* @returns {Promise<{[msg]: string, success: boolean, [item]: []}>} * @returns {Promise<{[msg]: string, success: boolean, [item]: []}>}
*/ */
async prependListItem({ server, db, key, values }) { async prependListItem({ server, db, key, values, reload }) {
try { try {
const { data, success, msg } = await AddListItem(server, db, key, 0, values) const { data, success, msg } = await AddListItem(server, db, key, 0, values)
if (success) { if (success) {
@ -1255,6 +1265,12 @@ const useBrowserStore = defineStore('browser', {
entries: left, entries: left,
prepend: true, prepend: true,
}) })
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
} }
return { success, item: left } return { success, item: left }
} else { } else {
@ -1271,9 +1287,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string[]} values * @param {string[]} values
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean, [item]: any[]}>} * @returns {Promise<{[msg]: string, success: boolean, [item]: any[]}>}
*/ */
async appendListItem({ server, db, key, values }) { async appendListItem({ server, db, key, values, reload }) {
try { try {
const { data, success, msg } = await AddListItem(server, db, key, 1, values) const { data, success, msg } = await AddListItem(server, db, key, 1, values)
if (success) { if (success) {
@ -1289,6 +1306,12 @@ const useBrowserStore = defineStore('browser', {
entries: right, entries: right,
prepend: false, prepend: false,
}) })
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
} }
return { success, item: right } return { success, item: right }
} else { } else {
@ -1310,6 +1333,7 @@ const useBrowserStore = defineStore('browser', {
* @param {formatTypes} format * @param {formatTypes} format
* @param {decodeTypes} [retDecode] * @param {decodeTypes} [retDecode]
* @param {formatTypes} [retFormat] * @param {formatTypes} [retFormat]
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async updateListItem({ async updateListItem({
@ -1322,6 +1346,7 @@ const useBrowserStore = defineStore('browser', {
format = formatTypes.RAW, format = formatTypes.RAW,
retDecode, retDecode,
retFormat, retFormat,
reload,
}) { }) {
try { try {
const { data, success, msg } = await SetListItem({ const { data, success, msg } = await SetListItem({
@ -1358,6 +1383,12 @@ const useBrowserStore = defineStore('browser', {
entries: removedIndex, entries: removedIndex,
}) })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }
@ -1373,9 +1404,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {number} index * @param {number} index
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean, [removed]: string[]}>} * @returns {Promise<{[msg]: string, success: boolean, [removed]: string[]}>}
*/ */
async removeListItem(server, db, key, index) { async removeListItem({ server, db, key, index, reload }) {
try { try {
const { data, success, msg } = await SetListItem({ server, db, key, index }) const { data, success, msg } = await SetListItem({ server, db, key, index })
if (success) { if (success) {
@ -1390,6 +1422,12 @@ const useBrowserStore = defineStore('browser', {
type: 'list', type: 'list',
entries: removedIndexes, entries: removedIndexes,
}) })
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
} }
return { success, removed } return { success, removed }
} else { } else {
@ -1406,9 +1444,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number} key * @param {string|number} key
* @param {string|string[]} value * @param {string|string[]} value
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async addSetItem(server, db, key, value) { async addSetItem({ server, db, key, value, reload }) {
try { try {
if ((!value) instanceof Array) { if ((!value) instanceof Array) {
value = [value] value = [value]
@ -1420,6 +1459,12 @@ const useBrowserStore = defineStore('browser', {
const tab = useTabStore() const tab = useTabStore()
tab.insertValueEntries({ server, db, key, type: 'set', entries: added }) tab.insertValueEntries({ server, db, key, type: 'set', entries: added })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }
@ -1440,6 +1485,7 @@ const useBrowserStore = defineStore('browser', {
* @param {formatTypes} [format] * @param {formatTypes} [format]
* @param {decodeTypes} [retDecode] * @param {decodeTypes} [retDecode]
* @param {formatTypes} [retFormat] * @param {formatTypes} [retFormat]
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async updateSetItem({ async updateSetItem({
@ -1452,6 +1498,7 @@ const useBrowserStore = defineStore('browser', {
format = formatTypes.RAW, format = formatTypes.RAW,
retDecode, retDecode,
retFormat, retFormat,
reload,
}) { }) {
try { try {
const { data, success, msg } = await UpdateSetItem({ const { data, success, msg } = await UpdateSetItem({
@ -1475,6 +1522,12 @@ const useBrowserStore = defineStore('browser', {
if (!isEmpty(added)) { if (!isEmpty(added)) {
tab.insertValueEntries({ server, db, key, type: 'set', entries: added }) tab.insertValueEntries({ server, db, key, type: 'set', entries: added })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success: false, msg } return { success: false, msg }
@ -1490,9 +1543,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string} value * @param {string} value
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async removeSetItem(server, db, key, value) { async removeSetItem({ server, db, key, value, reload }) {
try { try {
const { data, success, msg } = await SetSetItem(server, db, key, true, [value]) const { data, success, msg } = await SetSetItem(server, db, key, true, [value])
if (success) { if (success) {
@ -1502,6 +1556,12 @@ const useBrowserStore = defineStore('browser', {
const removedValues = map(removed, 'v') const removedValues = map(removed, 'v')
tab.removeValueEntries({ server, db, key, type: 'set', entries: removedValues }) tab.removeValueEntries({ server, db, key, type: 'set', entries: removedValues })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }
@ -1518,9 +1578,10 @@ const useBrowserStore = defineStore('browser', {
* @param {string|number[]} key * @param {string|number[]} key
* @param {number} action * @param {number} action
* @param {Object.<string, number>} vs value: score * @param {Object.<string, number>} vs value: score
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async addZSetItem(server, db, key, action, vs) { async addZSetItem({ server, db, key, action, vs, reload }) {
try { try {
const { data, success, msg } = await AddZSetValue(server, db, key, action, vs) const { data, success, msg } = await AddZSetValue(server, db, key, action, vs)
if (success) { if (success) {
@ -1532,6 +1593,12 @@ const useBrowserStore = defineStore('browser', {
if (!isEmpty(updated)) { if (!isEmpty(updated)) {
tab.updateValueEntries({ server, db, key, type: 'zset', entries: updated }) tab.updateValueEntries({ server, db, key, type: 'zset', entries: updated })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }
@ -1554,6 +1621,7 @@ const useBrowserStore = defineStore('browser', {
* @param {decodeTypes} [retDecode] * @param {decodeTypes} [retDecode]
* @param {formatTypes} [retFormat] * @param {formatTypes} [retFormat]
* @param {number} [index] index for retrieve affect entries quickly * @param {number} [index] index for retrieve affect entries quickly
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async updateZSetItem({ async updateZSetItem({
@ -1568,6 +1636,7 @@ const useBrowserStore = defineStore('browser', {
retDecode, retDecode,
retFormat, retFormat,
index, index,
reload,
}) { }) {
try { try {
const { data, success, msg } = await UpdateZSetValue({ const { data, success, msg } = await UpdateZSetValue({
@ -1598,6 +1667,12 @@ const useBrowserStore = defineStore('browser', {
if (!isEmpty(replaced)) { if (!isEmpty(replaced)) {
tab.replaceValueEntries({ server, db, key, type: 'zset', entries: replaced, index: [index] }) tab.replaceValueEntries({ server, db, key, type: 'zset', entries: replaced, index: [index] })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success, updated, removed } return { success, updated, removed }
} else { } else {
return { success, msg } return { success, msg }
@ -1613,9 +1688,10 @@ const useBrowserStore = defineStore('browser', {
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string} value * @param {string} value
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean, [removed]: []}>} * @returns {Promise<{[msg]: string, success: boolean, [removed]: []}>}
*/ */
async removeZSetItem(server, db, key, value) { async removeZSetItem({ server, db, key, value, reload }) {
try { try {
const { data, success, msg } = await UpdateZSetValue({ server, db, key, value, newValue: '', score: 0 }) const { data, success, msg } = await UpdateZSetValue({ server, db, key, value, newValue: '', score: 0 })
if (success) { if (success) {
@ -1625,6 +1701,12 @@ const useBrowserStore = defineStore('browser', {
const removeValues = map(removed, 'v') const removeValues = map(removed, 'v')
tab.removeValueEntries({ server, db, key, type: 'zset', entries: removeValues }) tab.removeValueEntries({ server, db, key, type: 'zset', entries: removeValues })
} }
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success, removed } return { success, removed }
} else { } else {
return { success, msg } return { success, msg }
@ -1641,9 +1723,10 @@ const useBrowserStore = defineStore('browser', {
* @param {string|number[]} key * @param {string|number[]} key
* @param {string} id * @param {string} id
* @param {string[]} values field1, value1, filed2, value2... * @param {string[]} values field1, value1, filed2, value2...
* @param {boolean} [reload]
* @returns {Promise<{[msg]: string, success: boolean}>} * @returns {Promise<{[msg]: string, success: boolean}>}
*/ */
async addStreamValue(server, db, key, id, values) { async addStreamValue({ server, db, key, id, values, reload }) {
try { try {
const { data = {}, success, msg } = await AddStreamValue(server, db, key, id, values) const { data = {}, success, msg } = await AddStreamValue(server, db, key, id, values)
if (success) { if (success) {
@ -1657,6 +1740,12 @@ const useBrowserStore = defineStore('browser', {
type: 'stream', type: 'stream',
entries: added, entries: added,
}) })
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
} }
return { success } return { success }
} else { } else {
@ -1669,21 +1758,28 @@ const useBrowserStore = defineStore('browser', {
/** /**
* remove stream field * remove stream field
* @param {string} connName * @param {string} server
* @param {number} db * @param {number} db
* @param {string|number[]} key * @param {string|number[]} key
* @param {string[]|string} ids * @param {string[]|string} ids
* @param {boolean} [reload]
* @returns {Promise<{[msg]: {}, success: boolean}>} * @returns {Promise<{[msg]: {}, success: boolean}>}
*/ */
async removeStreamValues(connName, db, key, ids) { async removeStreamValues({ server, db, key, ids, reload }) {
if (typeof ids === 'string') { if (typeof ids === 'string') {
ids = [ids] ids = [ids]
} }
try { try {
const { data = {}, success, msg } = await RemoveStreamValues(connName, db, key, ids) const { data = {}, success, msg } = await RemoveStreamValues(server, db, key, ids)
if (success) { if (success) {
const tab = useTabStore() const tab = useTabStore()
tab.removeValueEntries({ server: connName, db, key, type: 'stream', entries: ids }) tab.removeValueEntries({ server, db, key, type: 'stream', entries: ids })
if (reload === true) {
this.reloadKey({ server, db, key })
} else {
// reload summary only
this.loadKeySummary({ server, db, key })
}
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }

View File

@ -162,7 +162,7 @@ const useTabStore = defineStore('tab', {
}, },
openBlank(server) { openBlank(server) {
this.upsertTab({ server }) this.upsertTab({ server, clearValue: true })
}, },
/** /**
@ -177,9 +177,10 @@ const useTabStore = defineStore('tab', {
* @param {number} [size] * @param {number} [size]
* @param {number} [length] * @param {number} [length]
* @param {string} [matchPattern] * @param {string} [matchPattern]
* @param {boolean} [clearValue]
* @param {*} [value] * @param {*} [value]
*/ */
upsertTab({ subTab, server, db, type, ttl, key, keyCode, size, length, matchPattern = '' }) { upsertTab({ subTab, server, db, type, ttl, key, keyCode, size, length, matchPattern = '', clearValue }) {
let tabIndex = findIndex(this.tabList, { name: server }) let tabIndex = findIndex(this.tabList, { name: server })
if (tabIndex === -1) { if (tabIndex === -1) {
this.tabList.push({ this.tabList.push({
@ -213,7 +214,9 @@ const useTabStore = defineStore('tab', {
tab.size = size tab.size = size
tab.length = length tab.length = length
tab.matchPattern = matchPattern tab.matchPattern = matchPattern
tab.value = undefined if (clearValue === true) {
tab.value = undefined
}
} }
this._setActivatedIndex(tabIndex, true, subTab) this._setActivatedIndex(tabIndex, true, subTab)
// this.activatedTab = tab.name // this.activatedTab = tab.name
@ -224,14 +227,16 @@ const useTabStore = defineStore('tab', {
* @param {string} server * @param {string} server
* @param {number} db * @param {number} db
* @param {string} key * @param {string} key
* @param {*} value * @param {*} [value]
* @param {string} [format] * @param {string} [format]
* @param {string] [decode] * @param {string] [decode]
* @param {string} [matchPattern] * @param {string} [matchPattern]
* @param {boolean} [reset] * @param {boolean} [reset]
* @param {boolean} [end] keep end status if not set * @param {boolean} [end] keep end status if not set
* @param {number} [size]
* @param {number} [length]
*/ */
updateValue({ server, db, key, value, format, decode, matchPattern, reset, end }) { updateValue({ server, db, key, value, format, decode, matchPattern, reset, end, size = -1, length = -1 }) {
const tabData = find(this.tabList, { name: server, db, key }) const tabData = find(this.tabList, { name: server, db, key })
if (tabData == null) { if (tabData == null) {
return return
@ -240,6 +245,12 @@ const useTabStore = defineStore('tab', {
tabData.format = format || tabData.format tabData.format = format || tabData.format
tabData.decode = decode || tabData.decode tabData.decode = decode || tabData.decode
tabData.matchPattern = matchPattern || '' tabData.matchPattern = matchPattern || ''
if (size >= 0) {
tabData.size = size
}
if (length >= 0) {
tabData.length = length
}
if (typeof end === 'boolean') { if (typeof end === 'boolean') {
tabData.end = end tabData.end = end
} }