-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys_test.go
62 lines (54 loc) · 1.21 KB
/
keys_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
import (
"testing"
)
func TestKeys(t *testing.T) {
t.Run("all", func(t *testing.T) {
t.Run("randomkey", func(t *testing.T) {
testRandomKey(t)
})
t.Run("typekey", func(t *testing.T) {
testTypeKey(t)
})
testKeys(t)
})
}
func testKeys(t *testing.T) {
addr := "127.0.0.1:6379"
db := 4
client := NewRedisClient(addr, uint(db), "", 0)
if client == nil {
t.Fatalf("创建Redis实例错误, 地址:%s", addr)
}
keys, err := client.Keys("*")
if err != nil {
t.Fatalf("testkeys error: %s", err)
}
t.Logf("keys total is: %d", len(keys))
}
func testRandomKey(t *testing.T) {
addr := "127.0.0.1:6379"
db := 4
client := NewRedisClient(addr, uint(db), "", 0)
if client == nil {
t.Fatalf("创建Redis实例错误, 地址:%s", addr)
}
key, err := client.RandomKey()
if err != nil {
t.Fatalf("random error: %s", err)
}
t.Logf("randomkey: %s", key)
}
func testTypeKey(t *testing.T) {
addr := "127.0.0.1:6379"
db := 4
client := NewRedisClient(addr, uint(db), "", 0)
if client == nil {
t.Fatalf("创建Redis实例错误, 地址:%s", addr)
}
keytype, err := client.Type("g3")
if err != nil {
t.Fatalf("typekey error: %s", err)
}
t.Logf("g3 type is: %s", keytype)
}