From 07e15d2876ccc88afcd0f344a3eed6a050ff1921 Mon Sep 17 00:00:00 2001 From: Bogus Jung Date: Thu, 28 Apr 2022 20:32:20 +0900 Subject: [PATCH] fix: tags for structToMap "json" -> "key" --- commands.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 5ee66fab..ff096c6e 100644 --- a/commands.go +++ b/commands.go @@ -91,7 +91,7 @@ func structToMap(items interface{}) map[string]interface{} { v = v.Elem() } for i := 0; i < v.NumField(); i++ { - tag := v.Field(i).Tag.Get("json") + tag := v.Field(i).Tag.Get("key") if tag != "" && v.Field(i).Type.Kind() != reflect.Struct { field := reflectValue.Field(i).Interface() @@ -1285,7 +1285,10 @@ func (c cmdable) HMGet(ctx context.Context, key string, fields ...string) *Slice // - HSet("myhash", "key1", "value1", "key2", "value2") // - HSet("myhash", []string{"key1", "value1", "key2", "value2"}) // - HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"}) -// - HSet("myhash", struct{Key1: "value1"; Key2: "value2"}) +// +// Playing struct With "key" tag +// - type MyHash struct { Key1 string `key:"key1"`; Key2 int `key:"key2"` } +// - HSet("myhash", MyHash{"value1", "value2"}) // // Note that it requires Redis v4 for multiple field/value pairs support. func (c cmdable) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd {