This commit is contained in:
crusader
2017-09-01 15:42:23 +09:00
parent d3f40ec6be
commit 1e1e212954
15 changed files with 365 additions and 288 deletions

24
redis/pool.go Normal file
View File

@@ -0,0 +1,24 @@
package redis
import (
"context"
"time"
"git.loafle.net/commons_go/config"
"git.loafle.net/commons_go/logging"
rp "git.loafle.net/commons_go/redis_pool"
)
func NewPool(ctx context.Context) rp.Pool {
h := &poolHandlers{
ctx: ctx,
logger: logging.WithContext(ctx),
}
h.cfg = config.Sub("redis")
h.MaxIdle = h.cfg.GetInt("pool.MaxIdle")
h.IdleTimeout = h.cfg.GetDuration("pool.IdleTimeout") * time.Second
p := rp.NewPool(ctx, h)
return p
}

27
redis/pool_handlers.go Normal file
View File

@@ -0,0 +1,27 @@
package redis
import (
"context"
"time"
"github.com/garyburd/redigo/redis"
"git.loafle.net/commons_go/config"
rp "git.loafle.net/commons_go/redis_pool"
"go.uber.org/zap"
)
type poolHandlers struct {
rp.PoolHandlers
ctx context.Context
logger *zap.Logger
cfg config.Configurator
}
func (h *poolHandlers) Dial() (redis.Conn, error) {
return redis.Dial(h.cfg.GetString("network"), h.cfg.GetString("addr"))
}
func (h *poolHandlers) TestOnBorrow(c redis.Conn, t time.Time) error {
return nil
}