fix: incorrect parse node key

This commit is contained in:
tiny-craft 2023-08-20 14:28:53 +08:00
parent 50e9b54867
commit ae1d4f5215
1 changed files with 13 additions and 25 deletions

View File

@ -1,20 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { import { endsWith, get, isEmpty, join, remove, size, slice, sortedIndexBy, split, sumBy, toUpper, uniq } from 'lodash'
endsWith,
findLastIndex,
get,
isEmpty,
join,
lastIndexOf,
remove,
size,
slice,
sortedIndexBy,
split,
sumBy,
toUpper,
uniq,
} from 'lodash'
import { import {
AddHashField, AddHashField,
AddListItem, AddListItem,
@ -818,24 +803,27 @@ const useConnectionStore = defineStore('connections', {
* @return {DatabaseItem|null} * @return {DatabaseItem|null}
*/ */
getNode(key) { getNode(key) {
const p1 = split(key, '#', 1) const idx = key.indexOf('#')
let redisKey = null
// parse server and db index
const idx = p1[0].lastIndexOf('/db')
if (idx < 0) { if (idx < 0) {
return null return null
} }
const server = p1[0].substring(0, idx) const dbPart = key.substring(0, idx)
const db = parseInt(p1[0].substring(idx + 3)) // parse server and db index
const idx2 = dbPart.lastIndexOf('/db')
if (idx2 < 0) {
return null
}
const server = dbPart.substring(0, idx2)
const db = parseInt(dbPart.substring(idx2 + 3))
if (isNaN(db)) { if (isNaN(db)) {
return null return null
} }
if (size(p1) > 1) { if (size(key) > idx + 1) {
const keyPart = key.substring(idx + 1)
// contains redis key // contains redis key
redisKey = p1[1]
const nodeMap = this._getNodeMap(server, db) const nodeMap = this._getNodeMap(server, db)
return nodeMap.get(key) return nodeMap.get(keyPart)
} else { } else {
return this.databases[server][db] return this.databases[server][db]
} }