-
Notifications
You must be signed in to change notification settings - Fork 13
/
redis.go
56 lines (46 loc) · 982 Bytes
/
redis.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
package lib
import (
"github.com/garyburd/redigo/redis"
"time"
)
func NewPool(server, password string) *redis.Pool {
return &redis.Pool{
MaxIdle: 500,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", server)
if err != nil {
return nil, err
}
if len(password) > 0 {
if _, err := c.Do("AUTH", password); err != nil {
c.Close()
return nil, err
}
}
return c, err
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
}
var PoolQueue *redis.Pool
var PoolCache *redis.Pool
func SetQueuePool(pool *redis.Pool) {
PoolQueue = pool
}
func SetCachePool(pool *redis.Pool) {
PoolCache = pool
}
func GetQueuePool() *redis.Pool {
return PoolQueue
}
func GetCachePool() *redis.Pool {
return PoolCache
}
//var (
// redisServer = flag.String("redisServer", ":6379", "")
// redisPassword = flag.String("redisPassword", "", "")
//)