|
|
@ -9,7 +9,7 @@ import ( |
|
|
|
|
|
|
|
// 定义redis链接池
|
|
|
|
var Pool *redisdb.Pool |
|
|
|
var redisServerUrl string = "127.0.0.1:6379" |
|
|
|
var RedisServerUrl string = "127.0.0.1:6379" |
|
|
|
|
|
|
|
// func init() {
|
|
|
|
// if Pool == nil {
|
|
|
@ -18,7 +18,7 @@ var redisServerUrl string = "127.0.0.1:6379" |
|
|
|
// }
|
|
|
|
|
|
|
|
func Conn(server_url ...string) { |
|
|
|
var url string = "127.0.0.1:6379" |
|
|
|
var url string = RedisServerUrl |
|
|
|
if len(server_url) > 0 { |
|
|
|
url = server_url[0] |
|
|
|
} |
|
|
@ -37,7 +37,7 @@ func RedisInit(serverUrl string, max ...int) { |
|
|
|
} |
|
|
|
|
|
|
|
if serverUrl != "" { |
|
|
|
redisServerUrl = serverUrl |
|
|
|
RedisServerUrl = serverUrl |
|
|
|
} |
|
|
|
|
|
|
|
Pool = &redisdb.Pool{ |
|
|
@ -56,10 +56,12 @@ func redisConn() (redisdb.Conn, error) { |
|
|
|
writeTimeout := redisdb.DialWriteTimeout(time.Second * time.Duration(5)) |
|
|
|
conTimeout := redisdb.DialConnectTimeout(time.Second * time.Duration(2)) |
|
|
|
|
|
|
|
c, err := redisdb.Dial("tcp", redisServerUrl, dbOption, pwOption, readTimeout, writeTimeout, conTimeout) |
|
|
|
c, err := redisdb.Dial("tcp", RedisServerUrl, dbOption, pwOption, readTimeout, writeTimeout, conTimeout) |
|
|
|
if err != nil { |
|
|
|
log.Println("redis server connect failed", err) |
|
|
|
log.Println("redis connect failed", err) |
|
|
|
return nil, err |
|
|
|
} else { |
|
|
|
log.Println("redis connected", RedisServerUrl) |
|
|
|
} |
|
|
|
return c, nil |
|
|
|
} |