forked from xuyu/goredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_test.go
57 lines (50 loc) · 1.09 KB
/
redis_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
package goredis
import (
"fmt"
"testing"
"time"
)
var (
network = "tcp"
address = "127.0.0.1:6379"
db = 1
password = ""
timeout = 5 * time.Second
maxidle = 1
r *Redis
format = "tcp://auth:%s@%s/%d?timeout=%s&maxidle=%d"
)
func init() {
client, err := Dial(&DialConfig{network, address, db, password, timeout, maxidle})
if err != nil {
panic(err)
}
r = client
}
func TestDial(t *testing.T) {
redis, err := Dial(&DialConfig{network, address, db, password, timeout, maxidle})
if err != nil {
t.Error(err)
} else if err := redis.Ping(); err != nil {
t.Error(err)
}
redis.pool.Close()
}
func TestDialTimeout(t *testing.T) {
redis, err := Dial(&DialConfig{network, address, db, password, timeout, maxidle})
if err != nil {
t.Error(err)
} else if err := redis.Ping(); err != nil {
t.Error(err)
}
redis.pool.Close()
}
func TestDiaURL(t *testing.T) {
redis, err := DialURL(fmt.Sprintf(format, password, address, db, timeout.String(), maxidle))
if err != nil {
t.Fatal(err)
} else if err := redis.Ping(); err != nil {
t.Error(err)
}
redis.pool.Close()
}