-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_test.go
125 lines (114 loc) · 2.05 KB
/
key_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package redis_pack
import (
"testing"
)
func TestKeyRds_Key(t *testing.T) {
conn, _ := NewConnectionByPool(testPool)
type T struct {
Key string
Value float64
}
ts := []T{
{Key: "key1", Value: 1.1},
{Key: "key2", Value: 2.1},
{Key: "key3", Value: 2.2},
}
for _, one := range ts {
err := conn.String.Set(one.Key, one.Value).error
if err != nil {
t.Error(err)
}
}
key, err := conn.Key.RandomKey().String()
if err != nil {
t.Error(err)
}
for index, one := range ts {
if one.Key == key {
break
}
if index == len(ts) {
t.Error("randomkey 随机key出错")
}
}
for _, one := range ts {
err := conn.Key.Rename(one.Key, one.Key+"1").error
if err != nil {
t.Error(err)
}
}
for _, one := range ts {
exist, err := conn.Key.Exists(one.Key).Bool()
if err != nil {
t.Error(err)
}
if exist {
t.Error("rename 出错")
}
exist, err = conn.Key.Exists(one.Key + "1").Bool()
if err != nil {
t.Error(err)
}
if !exist {
t.Error("rename 出错")
}
}
for _, one := range ts {
err = conn.Key.Expire(one.Key+"1", 1000).error
if err != nil {
t.Error(err)
}
ttl, err := conn.Key.TTL(one.Key + "1").Int64()
if err != nil {
t.Error(err)
}
if ttl == -1 || ttl == -2 {
t.Error("过期key 失败")
}
}
for _, one := range ts {
err = conn.Key.Move(one.Key+"1", 2).error
if err != nil {
t.Error(err)
}
}
err = conn.Db.SelectDb(2).error
if err != nil {
t.Error(err)
}
for _, one := range ts {
exist, err := conn.Key.Exists(one.Key + "1").Bool()
if err != nil {
t.Error(err)
}
if !exist {
t.Error("move 出错")
}
}
}
func TestKeyRds_Del(t *testing.T) {
conn, _ := NewConnectionByPool(testPool)
key := "1"
err := conn.String.Set(key, 2, 10).error
if err != nil {
t.Error(err)
}
exist, err := conn.Key.Exists(key).Bool()
if err != nil {
t.Error(err)
}
if !exist {
t.Error(err)
}
err = conn.Key.Del(key).error
if err != nil {
t.Error(err)
}
exist, err = conn.Key.Exists(key).Bool()
if err != nil {
t.Error(err)
}
if exist {
t.Error(err)
}
}