fix: change serialize key "key" to "redis"

This commit is contained in:
정보교 2023-01-19 13:00:04 +09:00
parent 1fdcbf86bb
commit 913936b4cd
2 changed files with 6 additions and 6 deletions

View File

@ -91,7 +91,7 @@ func structToMap(items interface{}) map[string]interface{} {
v = v.Elem() v = v.Elem()
} }
for i := 0; i < v.NumField(); i++ { for i := 0; i < v.NumField(); i++ {
tag := v.Field(i).Tag.Get("key") tag := v.Field(i).Tag.Get("redis")
if tag != "" && v.Field(i).Type.Kind() != reflect.Struct { if tag != "" && v.Field(i).Type.Kind() != reflect.Struct {
field := reflectValue.Field(i).Interface() field := reflectValue.Field(i).Interface()
@ -1286,8 +1286,8 @@ func (c cmdable) HMGet(ctx context.Context, key string, fields ...string) *Slice
// - HSet("myhash", []string{"key1", "value1", "key2", "value2"}) // - HSet("myhash", []string{"key1", "value1", "key2", "value2"})
// - HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"}) // - HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})
// //
// Playing struct With "key" tag // Playing struct With "redis" tag
// - type MyHash struct { Key1 string `key:"key1"`; Key2 int `key:"key2"` } // - type MyHash struct { Key1 string `redis:"key1"`; Key2 int `redis:"key2"` }
// - HSet("myhash", MyHash{"value1", "value2"}) // - HSet("myhash", MyHash{"value1", "value2"})
// //
// Note that it requires Redis v4 for multiple field/value pairs support. // Note that it requires Redis v4 for multiple field/value pairs support.

View File

@ -198,10 +198,10 @@ func ExampleClient_SetEX() {
} }
func ExampleClient_HSet() { func ExampleClient_HSet() {
// Set "key" tag for hash key // Set "redis" tag for hash key
type ExampleUser struct { type ExampleUser struct {
Name string `key:"name"` Name string `redis:"name"`
Age int `key:"age"` Age int `redis:"age"`
} }
items := ExampleUser{"jane", 22} items := ExampleUser{"jane", 22}