|
|
@ -4,37 +4,38 @@ import ( |
|
|
|
"log" |
|
|
|
"time" |
|
|
|
|
|
|
|
"git.tetele.net/tgo/conf" |
|
|
|
|
|
|
|
redisdb "github.com/gomodule/redigo/redis" |
|
|
|
) |
|
|
|
|
|
|
|
// 定义redis链接池
|
|
|
|
var Pool *redisdb.Pool |
|
|
|
var RedisServerUrl string = conf.REDIS_SERVER + ":" + conf.REDIS_PORT |
|
|
|
|
|
|
|
// redis服务地址,如需更改,在api服务中设置
|
|
|
|
var RedisServerUrl string = "127.0.0.1:6379" |
|
|
|
|
|
|
|
// redis密码,如需更改,在api服务中设置
|
|
|
|
var RedisPassword string = "" |
|
|
|
|
|
|
|
var MaxActive, MaxIdle int |
|
|
|
|
|
|
|
// func init() {
|
|
|
|
// if Pool == nil {
|
|
|
|
// RedisInit()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
func Conn(server_url ...string) { |
|
|
|
var url, pwd string |
|
|
|
if len(server_url) > 0 { |
|
|
|
url = server_url[0] |
|
|
|
} |
|
|
|
if len(server_url) > 1 { |
|
|
|
pwd = server_url[1] |
|
|
|
} |
|
|
|
RedisInit(url, pwd) |
|
|
|
func Conn() { |
|
|
|
RedisInit(RedisServerUrl, RedisPassword, MaxActive, MaxIdle) |
|
|
|
} |
|
|
|
|
|
|
|
// 初始化redis链接池
|
|
|
|
/* |
|
|
|
* 初始化redis链接池 |
|
|
|
* @param serverUrl 服务地址 |
|
|
|
* @param password 密码 |
|
|
|
* @param max 最大的激活连接数,最大的空闲连接数 |
|
|
|
*/ |
|
|
|
func RedisInit(serverUrl, password string, max ...int) { |
|
|
|
|
|
|
|
var MaxActive, MaxIdle int |
|
|
|
if len(max) > 0 { |
|
|
|
MaxActive = max[0] |
|
|
|
} |
|
|
|