Compare commits
No commits in common. "v1.3.10" and "master" have entirely different histories.
15
go.sum
15
go.sum
@ -1,15 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s=
|
|
||||||
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/tylerb/gls v0.0.0-20150407001822-e606233f194d h1:yYYPFFlbqxF5mrj5sEfETtM/Ssz2LTy0/VKlDdXYctc=
|
|
||||||
github.com/tylerb/gls v0.0.0-20150407001822-e606233f194d/go.mod h1:0MwyId/pXK5wkYYEXe7NnVknX+aNBuF73fLV3U0reU8=
|
|
||||||
github.com/tylerb/is v2.1.4+incompatible h1:BMf2zP0kY2Ykzx2W1fDrjwKj1x1B4E0mELkpjaNy1tM=
|
|
||||||
github.com/tylerb/is v2.1.4+incompatible/go.mod h1:3Bw2NWEEe8Kx7/etYqgm9ug53iNDgabnloch75jjOSc=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
qoobing.com/gomod/log v1.2.8 h1:J1L87VhDMHvCgPZH2H/6QuwTLiMorJL97xVx7FJyi2g=
|
|
||||||
qoobing.com/gomod/log v1.2.8/go.mod h1:/ZTN/ukAbSqRb4eMlF9LpfkVgM21xwprbd5y3tcQxpM=
|
|
||||||
qoobing.com/gomod/str v1.0.1/go.mod h1:gbhN2dba/P5gFRGVJvEI57KEJLlMHHAd6Kuuxn4GlMY=
|
|
||||||
qoobing.com/gomod/str v1.0.5 h1:AXEB8k/yhepLK5jVez+WL4sWVuCFb8pWAgmo3nvt96A=
|
|
||||||
qoobing.com/gomod/str v1.0.5/go.mod h1:gbhN2dba/P5gFRGVJvEI57KEJLlMHHAd6Kuuxn4GlMY=
|
|
||||||
34
redis.go
34
redis.go
@ -1,39 +1,11 @@
|
|||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
redigo "github.com/gomodule/redigo/redis"
|
|
||||||
"qoobing.com/gomod/redis/redis"
|
"qoobing.com/gomod/redis/redis"
|
||||||
"qoobing.com/gomod/redis/sentinel"
|
"qoobing.com/gomod/redis/sentinel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type Config = sentinel.Config
|
||||||
Conn = redigo.Conn
|
|
||||||
Pool = redigo.Pool
|
|
||||||
Config = sentinel.Config
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var NewPool = redis.NewPool
|
||||||
NewRedisPool = redis.NewPool
|
var NewSentinelPool = sentinel.NewPool
|
||||||
NewSentinelPool = sentinel.NewPool
|
|
||||||
Int = redigo.Int
|
|
||||||
Int64 = redigo.Int64
|
|
||||||
Uint64 = redigo.Uint64
|
|
||||||
Float64 = redigo.Float64
|
|
||||||
String = redigo.String
|
|
||||||
Strings = redigo.Strings
|
|
||||||
Bool = redigo.Bool
|
|
||||||
Ints = redigo.Ints
|
|
||||||
Float64s = redigo.Float64s
|
|
||||||
Values = redigo.Values
|
|
||||||
ErrNil = redigo.ErrNil
|
|
||||||
ErrPoolExhausted = redigo.ErrPoolExhausted
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
logStdWriter = os.Stdout
|
||||||
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||||
logStdLogger = log.New(logStdWriter, logStdPrefix, logStdFlags)
|
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{
|
return &redis.Pool{
|
||||||
MaxIdle: *cfg.MaxIdle,
|
MaxIdle: *cfg.MaxIdle,
|
||||||
@ -69,7 +65,6 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
Dial: func() (redis.Conn, error) {
|
Dial: func() (redis.Conn, error) {
|
||||||
c, err := redis.Dial("tcp", masterAddr)
|
c, err := redis.Dial("tcp", masterAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErrLogger.Output(2, fmt.Sprintf("connect [%s] error: %s", masterAddr, err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +76,8 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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())
|
return nil, fmt.Errorf("redis master AUTH failed: <%s>", err.Error())
|
||||||
} else if okstr != "OK" {
|
} 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)
|
return nil, fmt.Errorf("redis master AUTH failed: <%s>", okstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,15 +29,6 @@ type Config struct {
|
|||||||
IdleTimeout *int `toml:"idle_timeout"` //空闲超时时间
|
IdleTimeout *int `toml:"idle_timeout"` //空闲超时时间
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg Config) GetSecDsn() (dsn string) {
|
|
||||||
if cfg.Master != "" {
|
|
||||||
dsn += fmt.Sprintf("mode=redis address=%s", cfg.Master)
|
|
||||||
} else if cfg.MasterName != "" {
|
|
||||||
dsn += fmt.Sprintf("mode=sentinel address=%s mastername=%s", cfg.Sentinels, cfg.MasterName)
|
|
||||||
}
|
|
||||||
return dsn
|
|
||||||
}
|
|
||||||
|
|
||||||
type Sentinel struct {
|
type Sentinel struct {
|
||||||
// Addrs is a slice with known Sentinel addresses.
|
// Addrs is a slice with known Sentinel addresses.
|
||||||
Addrs []string
|
Addrs []string
|
||||||
@ -130,10 +121,6 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
logStdWriter = os.Stdout
|
logStdWriter = os.Stdout
|
||||||
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||||
logStdLogger = log.New(logStdWriter, logStdPrefix, logStdFlags)
|
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{
|
return &redis.Pool{
|
||||||
MaxIdle: *cfg.MaxIdle,
|
MaxIdle: *cfg.MaxIdle,
|
||||||
@ -143,13 +130,11 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
Dial: func() (redis.Conn, error) {
|
Dial: func() (redis.Conn, error) {
|
||||||
masterAddr, err := sntnl.MasterAddr()
|
masterAddr, err := sntnl.MasterAddr()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErrLogger.Output(2, fmt.Sprintf("get master from sentinel error: %s", err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := redis.Dial("tcp", masterAddr)
|
c, err := redis.Dial("tcp", masterAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErrLogger.Output(2, fmt.Sprintf("connect [%s] error: %s", masterAddr, err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,10 +146,8 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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())
|
return nil, fmt.Errorf("redis master AUTH failed: <%s>", err.Error())
|
||||||
} else if okstr != "OK" {
|
} 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)
|
return nil, fmt.Errorf("redis master AUTH failed: <%s>", okstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +156,6 @@ func NewPool(cfg Config) *redis.Pool {
|
|||||||
err = fmt.Errorf(
|
err = fmt.Errorf(
|
||||||
"master(%s) got by name '%s' is not redis master",
|
"master(%s) got by name '%s' is not redis master",
|
||||||
masterAddr, masterName)
|
masterAddr, masterName)
|
||||||
logErrLogger.Output(2, err.Error())
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user