@@ -11,6 +11,7 @@ import (
1111type Model struct {
1212 Str1 string `redis:"str1"`
1313 Str2 string `redis:"str2"`
14+ Bytes []byte `redis:"bytes"`
1415 Int int `redis:"int"`
1516 Bool bool `redis:"bool"`
1617 Ignored struct {} `redis:"-"`
@@ -22,13 +23,15 @@ func main() {
2223 rdb := redis .NewClient (& redis.Options {
2324 Addr : ":6379" ,
2425 })
26+ _ = rdb .FlushDB (ctx ).Err ()
2527
2628 // Set some fields.
2729 if _ , err := rdb .Pipelined (ctx , func (rdb redis.Pipeliner ) error {
2830 rdb .HSet (ctx , "key" , "str1" , "hello" )
2931 rdb .HSet (ctx , "key" , "str2" , "world" )
3032 rdb .HSet (ctx , "key" , "int" , 123 )
3133 rdb .HSet (ctx , "key" , "bool" , 1 )
34+ rdb .HSet (ctx , "key" , "bytes" , []byte ("this is bytes !" ))
3235 return nil
3336 }); err != nil {
3437 panic (err )
@@ -47,5 +50,28 @@ func main() {
4750 }
4851
4952 spew .Dump (model1 )
53+ // Output:
54+ // (main.Model) {
55+ // Str1: (string) (len=5) "hello",
56+ // Str2: (string) (len=5) "world",
57+ // Bytes: ([]uint8) (len=15 cap=16) {
58+ // 00000000 74 68 69 73 20 69 73 20 62 79 74 65 73 20 21 |this is bytes !|
59+ // },
60+ // Int: (int) 123,
61+ // Bool: (bool) true,
62+ // Ignored: (struct {}) {
63+ // }
64+ // }
65+
5066 spew .Dump (model2 )
67+ // Output:
68+ // (main.Model) {
69+ // Str1: (string) (len=5) "hello",
70+ // Str2: (string) "",
71+ // Bytes: ([]uint8) <nil>,
72+ // Int: (int) 123,
73+ // Bool: (bool) false,
74+ // Ignored: (struct {}) {
75+ // }
76+ // }
5177}
0 commit comments