fix: compatible when the `INFO` command is unavailable

This commit is contained in:
Lykin 2024-08-07 11:25:54 +08:00
parent 868b0c81b6
commit a14e7e947e
1 changed files with 14 additions and 12 deletions

View File

@ -156,16 +156,17 @@ func (b *browserService) OpenConnection(name string) (resp types.JSResp) {
} else { } else {
// get database info // get database info
var res string var res string
res, err = client.Info(ctx, "keyspace").Result() info := map[string]map[string]string{}
if err != nil { if res, err = client.Info(ctx, "keyspace").Result(); err != nil {
resp.Msg = "get server info fail:" + err.Error() //resp.Msg = "get server info fail:" + err.Error()
return //return
} else {
info = b.parseInfo(res)
} }
info := b.parseInfo(res)
if totaldb <= 0 { if totaldb <= 0 {
// cannot retrieve the database count by "CONFIG GET databases", try to get max index from keyspace // cannot retrieve the database count by "CONFIG GET databases", try to get max index from keyspace
keyspace := info["Keyspace"] if keyspace := info["Keyspace"]; len(keyspace) > 0 {
var db, maxDB int var db, maxDB int
for dbName := range keyspace { for dbName := range keyspace {
if db, err = strconv.Atoi(strings.TrimLeft(dbName, "db")); err == nil { if db, err = strconv.Atoi(strings.TrimLeft(dbName, "db")); err == nil {
@ -176,6 +177,7 @@ func (b *browserService) OpenConnection(name string) (resp types.JSResp) {
} }
totaldb = maxDB + 1 totaldb = maxDB + 1
} }
}
queryDB := func(idx int) types.ConnectionDB { queryDB := func(idx int) types.ConnectionDB {
dbName := "db" + strconv.Itoa(idx) dbName := "db" + strconv.Itoa(idx)