fix: add bytes in scan struct example (#2836)

* fix: add bytes in scan struct example

Signed-off-by: rfyiamcool <rfyiamcool@163.com>

* fix: add bytes in scan struct example

Signed-off-by: rfyiamcool <rfyiamcool@163.com>

---------

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
This commit is contained in:
fengyun.rui 2024-02-15 04:22:32 +08:00 committed by GitHub
parent 9133749cd3
commit 7b9e81fd41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
type Model struct {
Str1 string `redis:"str1"`
Str2 string `redis:"str2"`
Bytes []byte `redis:"bytes"`
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", "bytes", []byte("this is bytes !"))
return nil
}); err != nil {
panic(err)
@ -47,5 +50,28 @@ func main() {
}
spew.Dump(model1)
// Output:
// (main.Model) {
// Str1: (string) (len=5) "hello",
// Str2: (string) (len=5) "world",
// 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,
// Bool: (bool) true,
// Ignored: (struct {}) {
// }
// }
spew.Dump(model2)
// Output:
// (main.Model) {
// Str1: (string) (len=5) "hello",
// Str2: (string) "",
// Bytes: ([]uint8) <nil>,
// Int: (int) 123,
// Bool: (bool) false,
// Ignored: (struct {}) {
// }
// }
}