overflow_gateway_websocket/external/redis/pool.go

41 lines
865 B
Go
Raw Permalink Normal View History

2017-11-10 13:24:10 +00:00
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 {
2018-03-21 11:17:31 +00:00
logging.Logger().Panicf("App: %v", err)
2017-11-10 13:24:10 +00:00
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)
}