|
|
@@ -34,6 +34,7 @@ type Config struct { |
|
|
|
} |
|
|
|
|
|
|
|
var pool *redigo.Pool |
|
|
|
var redisConn redigo.Conn |
|
|
|
var conf *Config |
|
|
|
|
|
|
|
func NewRedis(addr string) { |
|
|
@@ -75,9 +76,23 @@ func NewRedis(addr string) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func NewRedisConn(conn redigo.Conn) { |
|
|
|
redisConn = conn |
|
|
|
} |
|
|
|
|
|
|
|
// |
|
|
|
//func Do(cmd string, args ...interface{}) (reply interface{}, err error) { |
|
|
|
// conn := pool.Get() |
|
|
|
// defer conn.Close() |
|
|
|
// return conn.Do(cmd, args...) |
|
|
|
//} |
|
|
|
|
|
|
|
func Do(cmd string, args ...interface{}) (reply interface{}, err error) { |
|
|
|
conn := pool.Get() |
|
|
|
defer conn.Close() |
|
|
|
var conn = redisConn |
|
|
|
if redisConn == nil { |
|
|
|
conn = pool.Get() |
|
|
|
defer conn.Close() |
|
|
|
} |
|
|
|
return conn.Do(cmd, args...) |
|
|
|
} |
|
|
|
|
|
|
|