diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 8ceb6a8..5d276b4 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -9,6 +9,7 @@ import ( "golang.org/x/crypto/ssh" "net" "os" + "slices" "strconv" "strings" "sync" @@ -261,11 +262,16 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) { return } - // get total databases + // get connection config + selConn := c.conns.GetConnection(name) + totaldb := 16 - if config, err := rdb.ConfigGet(ctx, "databases").Result(); err == nil { - if total, err := strconv.Atoi(config["databases"]); err == nil { - totaldb = total + if selConn.DBFilterType == "none" { + // get total databases + if config, err := rdb.ConfigGet(ctx, "databases").Result(); err == nil { + if total, err := strconv.Atoi(config["databases"]); err == nil { + totaldb = total + } } } @@ -278,21 +284,37 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) { // Parse all db, response content like below var dbs []types.ConnectionDB info := c.parseInfo(res) - for i := 0; i < totaldb; i++ { - dbName := "db" + strconv.Itoa(i) + queryDB := func(idx int) types.ConnectionDB { + dbName := "db" + strconv.Itoa(idx) dbInfoStr := info["Keyspace"][dbName] if len(dbInfoStr) > 0 { dbInfo := c.parseDBItemInfo(dbInfoStr) - dbs = append(dbs, types.ConnectionDB{ + return types.ConnectionDB{ Name: dbName, Keys: dbInfo["keys"], Expires: dbInfo["expires"], AvgTTL: dbInfo["avg_ttl"], - }) + } } else { - dbs = append(dbs, types.ConnectionDB{ + return types.ConnectionDB{ Name: dbName, - }) + } + } + } + switch selConn.DBFilterType { + case "none": + for idx := 0; idx < totaldb; idx++ { + dbs = append(dbs, queryDB(idx)) + } + case "show": + for _, idx := range selConn.DBFilterList { + dbs = append(dbs, queryDB(idx)) + } + case "hide": + for idx := 0; idx < totaldb; idx++ { + if !slices.Contains(selConn.DBFilterList, idx) { + dbs = append(dbs, queryDB(idx)) + } } } @@ -350,7 +372,7 @@ func (c *connectionService) getRedisClient(connName string, db int) (*redis.Clie }) })) - if _, err := rdb.Ping(c.ctx).Result(); err != nil && err != redis.Nil { + if _, err = rdb.Ping(c.ctx).Result(); err != nil && err != redis.Nil { return nil, nil, errors.New("can not connect to redis server:" + err.Error()) } var cancelFunc context.CancelFunc diff --git a/backend/storage/connections.go b/backend/storage/connections.go index 7b31b1f..96b7394 100644 --- a/backend/storage/connections.go +++ b/backend/storage/connections.go @@ -34,6 +34,8 @@ func (c *ConnectionsStorage) defaultConnectionItem() types.ConnectionConfig { KeySeparator: ":", ConnTimeout: 60, ExecTimeout: 60, + DBFilterType: "none", + DBFilterList: []int{}, MarkColor: "", } } diff --git a/backend/types/connection.go b/backend/types/connection.go index c384d19..d9b4d75 100644 --- a/backend/types/connection.go +++ b/backend/types/connection.go @@ -13,6 +13,8 @@ type ConnectionConfig struct { KeySeparator string `json:"keySeparator,omitempty" yaml:"key_separator,omitempty"` ConnTimeout int `json:"connTimeout,omitempty" yaml:"conn_timeout,omitempty"` ExecTimeout int `json:"execTimeout,omitempty" yaml:"exec_timeout,omitempty"` + DBFilterType string `json:"dbFilterType" yaml:"db_filter_type,omitempty"` + DBFilterList []int `json:"dbFilterList" yaml:"db_filter_list,omitempty"` MarkColor string `json:"markColor,omitempty" yaml:"mark_color,omitempty"` SSH ConnectionSSH `json:"ssh,omitempty" yaml:"ssh,omitempty"` } diff --git a/frontend/src/components/dialogs/ConnectionDialog.vue b/frontend/src/components/dialogs/ConnectionDialog.vue index e7ea165..38d1f48 100644 --- a/frontend/src/components/dialogs/ConnectionDialog.vue +++ b/frontend/src/components/dialogs/ConnectionDialog.vue @@ -1,5 +1,5 @@