43 lines
885 B
Go
43 lines
885 B
Go
package redis
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.loafle.net/overflow/overflow_gateway_websocket/config"
|
|
|
|
"git.loafle.net/commons_go/logging"
|
|
crp "git.loafle.net/commons_go/redis_pool"
|
|
"github.com/garyburd/redigo/redis"
|
|
)
|
|
|
|
var RedisPool crp.Pool
|
|
|
|
func ExternalInit() {
|
|
ph := &redisPoolHandlers{}
|
|
ph.MaxCapacity = config.Config.Redis.Pool.MaxCapacity
|
|
ph.MaxIdle = config.Config.Redis.Pool.MaxIdle
|
|
ph.IdleTimeout = config.Config.Redis.Pool.IdleTimeout
|
|
ph.Wait = config.Config.Redis.Pool.Wait
|
|
|
|
RedisPool = crp.New(ph)
|
|
|
|
if err := RedisPool.Start(); nil != err {
|
|
logging.Logger().Panic(fmt.Sprintf("App: %v", err))
|
|
return
|
|
}
|
|
}
|
|
|
|
func ExternalDestroy() {
|
|
if nil != RedisPool {
|
|
RedisPool.Stop()
|
|
}
|
|
}
|
|
|
|
type redisPoolHandlers struct {
|
|
crp.PoolHandlers
|
|
}
|
|
|
|
func (ph *redisPoolHandlers) Dial() (redis.Conn, error) {
|
|
return redis.Dial(config.Config.Redis.Network, config.Config.Redis.Addr)
|
|
}
|