overflow_gateway_websocket/external/redis/pool.go
crusader 8f3e430ac8 ing
2018-03-21 20:17:31 +09:00

41 lines
865 B
Go

package redis
import (
"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().Panicf("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)
}