-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
62 lines (48 loc) · 1.18 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package redis_test
import (
"context"
"testing"
"github.com/go-redis/redis/v8"
"github.com/vmihailenco/msgpack"
)
type student struct {
Name string
Family string
}
func TestMain(t *testing.T) {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
pong, err := client.Ping(context.TODO()).Result()
if err != nil {
t.Fatalf("Ping Error: %s", err)
}
t.Logf("Ping Success: %s", pong)
s1, err := msgpack.Marshal(student{
Name: "Parham",
Family: "Alvani",
})
if err != nil {
t.Fatalf("Student to msgpack marshaling: %s", err)
}
t.Log(client.RPush(context.TODO(), "students-list", s1).Result())
s2, err := msgpack.Marshal(student{
Name: "Navid",
Family: "Mashayekhi",
})
if err != nil {
t.Fatalf("Student to msgpack marshaling: %s", err)
}
t.Log(client.RPush(context.TODO(), "students-list", s2).Result())
var s3 student
result, err := client.RPop(context.TODO(), "students-list").Bytes()
if err != nil {
t.Fatalf("Pop Error: %s", err)
}
if err := msgpack.Unmarshal(result, &s3); err != nil {
t.Fatalf("Msgpack to student unmarshaling: %s", err)
}
t.Log(s3)
}