redis: handle data browsing for different typed keys
This commit is contained in:
parent
b45faa2e73
commit
8f105183eb
42
db_redis.go
42
db_redis.go
@ -84,19 +84,53 @@ func (ld *redisLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
||||
colKey.SetCaption("Key")
|
||||
colKey.SetWidth(MY_WIDTH)
|
||||
colKey.SetAlignment(types.TaLeftJustify)
|
||||
colType := f.contentBox.Columns().Add()
|
||||
colType.SetCaption("Type")
|
||||
colVal := f.contentBox.Columns().Add()
|
||||
colVal.SetCaption("Value")
|
||||
|
||||
for _, key := range allKeys {
|
||||
val, err := ld.db.Get(ctx, key).Result()
|
||||
typeName, err := ld.db.Type(ctx, key).Result()
|
||||
if err != nil {
|
||||
vcl.ShowMessage(fmt.Sprintf("Listing keys in database %q: %v", ndata.bucketPath[0], err))
|
||||
vcl.ShowMessage(fmt.Sprintf("Loading %q/%q: %v", ndata.bucketPath[0], key, err))
|
||||
return
|
||||
}
|
||||
|
||||
dataEntry := f.contentBox.Items().Add()
|
||||
dataEntry.SetCaption(key) // formatUtf8
|
||||
dataEntry.SubItems().Add(val) // formatUtf8
|
||||
dataEntry.SetCaption(key) // formatUtf8
|
||||
dataEntry.SubItems().Add(typeName)
|
||||
|
||||
switch typeName {
|
||||
case "string":
|
||||
val, err := ld.db.Get(ctx, key).Result()
|
||||
if err != nil {
|
||||
vcl.ShowMessage(fmt.Sprintf("Loading %q/%q: %v", ndata.bucketPath[0], key, err))
|
||||
return
|
||||
}
|
||||
dataEntry.SubItems().Add(val)
|
||||
|
||||
case "hash":
|
||||
val, err := ld.db.HGetAll(ctx, key).Result()
|
||||
if err != nil {
|
||||
vcl.ShowMessage(fmt.Sprintf("Loading %q/%q: %v", ndata.bucketPath[0], key, err))
|
||||
return
|
||||
}
|
||||
// It's a map[string]string
|
||||
dataEntry.SubItems().Add(formatAny(val))
|
||||
|
||||
case "lists":
|
||||
fallthrough
|
||||
case "sets":
|
||||
fallthrough
|
||||
case "sorted sets":
|
||||
fallthrough
|
||||
case "stream":
|
||||
fallthrough
|
||||
|
||||
default:
|
||||
dataEntry.SubItems().Add("<<<other object type>>>")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Valid
|
||||
|
Loading…
Reference in New Issue
Block a user