redis: handle data browsing for different typed keys

This commit is contained in:
mappu 2024-06-23 15:57:20 +12:00
parent b45faa2e73
commit 8f105183eb
1 changed files with 38 additions and 4 deletions

View File

@ -84,19 +84,53 @@ func (ld *redisLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
colKey.SetCaption("Key") colKey.SetCaption("Key")
colKey.SetWidth(MY_WIDTH) colKey.SetWidth(MY_WIDTH)
colKey.SetAlignment(types.TaLeftJustify) colKey.SetAlignment(types.TaLeftJustify)
colType := f.contentBox.Columns().Add()
colType.SetCaption("Type")
colVal := f.contentBox.Columns().Add() colVal := f.contentBox.Columns().Add()
colVal.SetCaption("Value") colVal.SetCaption("Value")
for _, key := range allKeys { for _, key := range allKeys {
val, err := ld.db.Get(ctx, key).Result() typeName, err := ld.db.Type(ctx, key).Result()
if err != nil { 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 return
} }
dataEntry := f.contentBox.Items().Add() dataEntry := f.contentBox.Items().Add()
dataEntry.SetCaption(key) // formatUtf8 dataEntry.SetCaption(key) // formatUtf8
dataEntry.SubItems().Add(val) // 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 // Valid