-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgotest_client.go
45 lines (37 loc) · 870 Bytes
/
gotest_client.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
package redisutil
import (
"fmt"
"sync"
"github.com/cclehui/redisutil/internal/test"
"github.com/gomodule/redigo/redis"
)
// gotest 所用的client
var gotestRedisPool *redis.Pool
var gotestRedisPoolOnce sync.Once
func getTestPool() *redis.Pool {
gotestRedisPoolOnce.Do(func() {
server := fmt.Sprintf("%s:%d", test.Conf.Redis.Endpoint.Address, test.Conf.Redis.Endpoint.Port)
gotestRedisPool = &redis.Pool{
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", server)
if err != nil {
return nil, err
}
if test.Conf.Redis.Auth != "" {
if _, err := c.Do("AUTH", test.Conf.Redis.Auth); err != nil {
c.Close()
return nil, err
}
}
/*
if _, err := c.Do("SELECT", db); err != nil {
c.Close()
return nil, err
}
*/
return c, nil
},
}
})
return gotestRedisPool
}