Compare commits
No commits in common. "main" and "master" have entirely different histories.
18
redis.go
18
redis.go
@ -1,25 +1,11 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
redigo "github.com/gomodule/redigo/redis"
|
||||
"qoobing.com/gomod/redis/redis"
|
||||
"qoobing.com/gomod/redis/sentinel"
|
||||
)
|
||||
|
||||
type (
|
||||
Conn = redigo.Conn
|
||||
Pool = redigo.Pool
|
||||
Config = sentinel.Config
|
||||
)
|
||||
type Config = sentinel.Config
|
||||
|
||||
var NewRedisPool = redis.NewPool
|
||||
var NewPool = redis.NewPool
|
||||
var NewSentinelPool = sentinel.NewPool
|
||||
|
||||
func NewPool(cfg Config) *redigo.Pool {
|
||||
if cfg.Master != "" {
|
||||
return NewRedisPool(cfg)
|
||||
} else if cfg.MasterName != "" {
|
||||
return NewSentinelPool(cfg)
|
||||
}
|
||||
panic("invalid config: Master & MasterName are both empty")
|
||||
}
|
||||
|
@ -56,10 +56,6 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
logStdWriter = os.Stdout
|
||||
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||
logStdLogger = log.New(logStdWriter, logStdPrefix, logStdFlags)
|
||||
logErrPrefix = "ERRO "
|
||||
logErrWriter = os.Stderr
|
||||
logErrFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||
logErrLogger = log.New(logErrWriter, logErrPrefix, logErrFlags)
|
||||
)
|
||||
return &redis.Pool{
|
||||
MaxIdle: *cfg.MaxIdle,
|
||||
@ -69,7 +65,6 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
Dial: func() (redis.Conn, error) {
|
||||
c, err := redis.Dial("tcp", masterAddr)
|
||||
if err != nil {
|
||||
logErrLogger.Output(2, fmt.Sprintf("connect [%s] error: %s", masterAddr, err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -81,10 +76,8 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logErrLogger.Output(2, fmt.Sprintf("auth [%s] error: %s", masterAddr, err))
|
||||
return nil, fmt.Errorf("redis master AUTH failed: <%s>", err.Error())
|
||||
} else if okstr != "OK" {
|
||||
logErrLogger.Output(2, fmt.Sprintf("auth [%s] not return ok but '%s'", masterAddr, okstr))
|
||||
return nil, fmt.Errorf("redis master AUTH failed: <%s>", okstr)
|
||||
}
|
||||
|
||||
|
@ -121,10 +121,6 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
logStdWriter = os.Stdout
|
||||
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||
logStdLogger = log.New(logStdWriter, logStdPrefix, logStdFlags)
|
||||
logErrPrefix = "ERRO "
|
||||
logErrWriter = os.Stderr
|
||||
logErrFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||
logErrLogger = log.New(logErrWriter, logErrPrefix, logErrFlags)
|
||||
)
|
||||
return &redis.Pool{
|
||||
MaxIdle: *cfg.MaxIdle,
|
||||
@ -134,13 +130,11 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
Dial: func() (redis.Conn, error) {
|
||||
masterAddr, err := sntnl.MasterAddr()
|
||||
if err != nil {
|
||||
logErrLogger.Output(2, fmt.Sprintf("get master from sentinel error: %s", err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err := redis.Dial("tcp", masterAddr)
|
||||
if err != nil {
|
||||
logErrLogger.Output(2, fmt.Sprintf("connect [%s] error: %s", masterAddr, err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -152,10 +146,8 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logErrLogger.Output(2, fmt.Sprintf("auth [%s] error: %s", masterAddr, err))
|
||||
return nil, fmt.Errorf("redis master AUTH failed: <%s>", err.Error())
|
||||
} else if okstr != "OK" {
|
||||
logErrLogger.Output(2, fmt.Sprintf("auth [%s] not return ok but '%s'", masterAddr, okstr))
|
||||
return nil, fmt.Errorf("redis master AUTH failed: <%s>", okstr)
|
||||
}
|
||||
|
||||
@ -164,7 +156,6 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
err = fmt.Errorf(
|
||||
"master(%s) got by name '%s' is not redis master",
|
||||
masterAddr, masterName)
|
||||
logErrLogger.Output(2, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user