From 0d70f609234094e86545ee068cf7da43da8d10ff Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 18 Dec 2023 00:21:14 +0800 Subject: [PATCH 1/2] fix: add bytes in scan struct example Signed-off-by: rfyiamcool --- example/scan-struct/main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/example/scan-struct/main.go b/example/scan-struct/main.go index 9d270b530..8f2d7099c 100644 --- a/example/scan-struct/main.go +++ b/example/scan-struct/main.go @@ -11,6 +11,7 @@ import ( type Model struct { Str1 string `redis:"str1"` Str2 string `redis:"str2"` + Bytes1 []byte `redis:"bytes1"` Int int `redis:"int"` Bool bool `redis:"bool"` Ignored struct{} `redis:"-"` @@ -22,6 +23,7 @@ func main() { rdb := redis.NewClient(&redis.Options{ Addr: ":6379", }) + _ = rdb.FlushDB(ctx).Err() // Set some fields. if _, err := rdb.Pipelined(ctx, func(rdb redis.Pipeliner) error { @@ -29,6 +31,7 @@ func main() { rdb.HSet(ctx, "key", "str2", "world") rdb.HSet(ctx, "key", "int", 123) rdb.HSet(ctx, "key", "bool", 1) + rdb.HSet(ctx, "key", "bytes1", []byte("this is bytes !")) return nil }); err != nil { panic(err) @@ -47,5 +50,29 @@ func main() { } spew.Dump(model1) + // Output: + // (main.Model) { + // Str1: (string) (len=5) "hello", + // Str2: (string) (len=5) "world", + // Bytes1: ([]uint8) (len=15 cap=16) { + // 00000000 74 68 69 73 20 69 73 20 62 79 74 65 73 20 21 |this is bytes !| + // }, + // Int: (int) 123, + // Bool: (bool) true, + // Ignored: (struct {}) { + // } + // } + spew.Dump(model2) + // Output: + // (main.Model) { + // Str1: (string) (len=5) "hello", + // Str2: (string) "", + // Bytes1: ([]uint8) , + // Int: (int) 123, + // Bool: (bool) false, + // Ignored: (struct {}) { + // } + // } + } From 745fbf232b326f4f9ebddeaece6b6401be35cd50 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 18 Dec 2023 00:22:44 +0800 Subject: [PATCH 2/2] fix: add bytes in scan struct example Signed-off-by: rfyiamcool --- example/scan-struct/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/example/scan-struct/main.go b/example/scan-struct/main.go index 8f2d7099c..cc877b847 100644 --- a/example/scan-struct/main.go +++ b/example/scan-struct/main.go @@ -11,7 +11,7 @@ import ( type Model struct { Str1 string `redis:"str1"` Str2 string `redis:"str2"` - Bytes1 []byte `redis:"bytes1"` + Bytes []byte `redis:"bytes"` Int int `redis:"int"` Bool bool `redis:"bool"` Ignored struct{} `redis:"-"` @@ -31,7 +31,7 @@ func main() { rdb.HSet(ctx, "key", "str2", "world") rdb.HSet(ctx, "key", "int", 123) rdb.HSet(ctx, "key", "bool", 1) - rdb.HSet(ctx, "key", "bytes1", []byte("this is bytes !")) + rdb.HSet(ctx, "key", "bytes", []byte("this is bytes !")) return nil }); err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // (main.Model) { // Str1: (string) (len=5) "hello", // Str2: (string) (len=5) "world", - // Bytes1: ([]uint8) (len=15 cap=16) { + // Bytes: ([]uint8) (len=15 cap=16) { // 00000000 74 68 69 73 20 69 73 20 62 79 74 65 73 20 21 |this is bytes !| // }, // Int: (int) 123, @@ -68,11 +68,10 @@ func main() { // (main.Model) { // Str1: (string) (len=5) "hello", // Str2: (string) "", - // Bytes1: ([]uint8) , + // Bytes: ([]uint8) , // Int: (int) 123, // Bool: (bool) false, // Ignored: (struct {}) { // } // } - }