ing
This commit is contained in:
24
redis/pool.go
Normal file
24
redis/pool.go
Normal 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
27
redis/pool_handlers.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user