@@ -11,6 +11,7 @@ import (
11
11
type Model struct {
12
12
Str1 string `redis:"str1"`
13
13
Str2 string `redis:"str2"`
14
+ Bytes []byte `redis:"bytes"`
14
15
Int int `redis:"int"`
15
16
Bool bool `redis:"bool"`
16
17
Ignored struct {} `redis:"-"`
@@ -22,13 +23,15 @@ func main() {
22
23
rdb := redis .NewClient (& redis.Options {
23
24
Addr : ":6379" ,
24
25
})
26
+ _ = rdb .FlushDB (ctx ).Err ()
25
27
26
28
// Set some fields.
27
29
if _ , err := rdb .Pipelined (ctx , func (rdb redis.Pipeliner ) error {
28
30
rdb .HSet (ctx , "key" , "str1" , "hello" )
29
31
rdb .HSet (ctx , "key" , "str2" , "world" )
30
32
rdb .HSet (ctx , "key" , "int" , 123 )
31
33
rdb .HSet (ctx , "key" , "bool" , 1 )
34
+ rdb .HSet (ctx , "key" , "bytes" , []byte ("this is bytes !" ))
32
35
return nil
33
36
}); err != nil {
34
37
panic (err )
@@ -47,5 +50,28 @@ func main() {
47
50
}
48
51
49
52
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
+
50
66
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
+ // }
51
77
}
0 commit comments