forked from mirror/ledisdb
add replaciton master auth support (#336)
This commit is contained in:
parent
17ea9a433d
commit
36de957bf3
|
@ -83,6 +83,7 @@ type ReplicationConfig struct {
|
|||
SyncLog int `toml:"sync_log"`
|
||||
Compression bool `toml:"compression"`
|
||||
UseMmap bool `toml:"use_mmap"`
|
||||
MasterPassword string `toml:"master_password"`
|
||||
}
|
||||
|
||||
type SnapshotConfig struct {
|
||||
|
|
|
@ -110,12 +110,35 @@ func (m *master) checkConn() error {
|
|||
var err error
|
||||
if m.conn == nil {
|
||||
m.conn, err = goredis.Connect(m.addr)
|
||||
} else {
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// already connected and has master password
|
||||
if len(m.app.cfg.Replication.MasterPassword) != 0 {
|
||||
var res string
|
||||
|
||||
res, err = goredis.String(m.conn.Do("auth", m.app.cfg.Replication.MasterPassword))
|
||||
|
||||
if err != nil || strings.ToUpper(res) != "OK" {
|
||||
m.conn.Close()
|
||||
m.conn = nil
|
||||
|
||||
if err == nil {
|
||||
err = fmt.Errorf("master auth fail , res=%s , password=%s", res, m.app.cfg.Replication.MasterPassword)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = m.conn.Do("PING"); err != nil {
|
||||
m.conn.Close()
|
||||
m.conn = nil
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue