yuriy0803 3 years ago
parent
commit
d8c87e3e45
  1. 9
      api.json
  2. 6
      proxy/proxy.go
  3. 38
      storage/redis.go

9
api.json

@ -93,7 +93,14 @@
"endpoint": "127.0.0.1:6379",
"poolSize": 10,
"database": 0,
"password": ""
"password": "",
"sentinelEnabled": false,
"masterName": "mymaster",
"sentinelAddrs": [
"127.0.0.1:26379",
"127.0.0.1:26389",
"127.0.0.1:26399"
]
},
"exchange": {

6
proxy/proxy.go

@ -169,6 +169,12 @@ func (s *ProxyServer) rpc() *rpc.RPCClient {
}
func (s *ProxyServer) checkUpstreams() {
idx := atomic.LoadInt32(&s.upstream)
current := s.upstreams[idx]
if current.Check() {
return
}
candidate := int32(0)
backup := false

38
storage/redis.go

@ -16,10 +16,13 @@ import (
)
type Config struct {
Endpoint string `json:"endpoint"`
Password string `json:"password"`
Database int64 `json:"database"`
PoolSize int `json:"poolSize"`
SentinelEnabled bool `json:"sentinelEnabled"`
Endpoint string `json:"endpoint"`
Password string `json:"password"`
Database int64 `json:"database"`
PoolSize int `json:"poolSize"`
MasterName string `json:"masterName"`
SentinelAddrs []string `json:"sentinelAddrs"`
}
type RedisClient struct {
@ -156,16 +159,25 @@ type Worker struct {
}
func NewRedisClient(cfg *Config, prefix string, pplns int64, CoinName string) *RedisClient {
options := redis.Options{
Addr: cfg.Endpoint,
Password: cfg.Password,
DB: cfg.Database,
PoolSize: cfg.PoolSize,
}
if cfg.Endpoint[0:1] == "/" {
options.Network = "unix"
var client *redis.Client
if cfg.SentinelEnabled && len(cfg.MasterName) != 0 && len(cfg.SentinelAddrs) != 0 {
// sentinel mode
client = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: cfg.MasterName,
SentinelAddrs: cfg.SentinelAddrs,
Password: cfg.Password,
DB: cfg.Database,
PoolSize: cfg.PoolSize,
})
} else {
// single instance
client = redis.NewClient(&redis.Options{
Addr: cfg.Endpoint,
Password: cfg.Password,
DB: cfg.Database,
PoolSize: cfg.PoolSize,
})
}
client := redis.NewClient(&options)
return &RedisClient{client: client, prefix: prefix, pplns: pplns, CoinName: CoinName}
}

Loading…
Cancel
Save