Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
moredure committed Feb 1, 2019
1 parent 1a2ad64 commit db1fcb5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions redis_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ func (m *redisMigrator) Migrate() {

func (m *redisMigrator) prepareTo() {
if err := m.To.ConfigSet("slave-read-only", "yes").Err(); err != nil {
panic(err)
log.Fatalf("failed to set slave-read-only to yes with error %v\n", err)
}
if err := m.To.ConfigSet("masterauth", m.From.Options().Password).Err(); err != nil {
panic(err)
log.Fatalf("failed to set masterauth password with error %v\n", err)
}
if host, port, err := net.SplitHostPort(m.From.Options().Addr); err != nil {
panic(err)
log.Fatalf("failed to split host port of source redis with error %v\n", err)
} else if err := m.To.SlaveOf(host, port).Err(); err != nil {
panic(err)
log.Fatalf("failed to make target slave of host %s port %s with error %v\n", host, port, err)
}
}

func (m *redisMigrator) waitForUp() {
info := new(Info)
for {
if err := m.To.Info().Scan(info); err != nil {
panic(err)
log.Fatalf("failed to scan info with error %v\n", err)
}
if info.MasterLinkStatus == "up" {
return
Expand All @@ -54,7 +54,7 @@ func (m *redisMigrator) waitForComplete() {
var clientList ClientList
for {
if err := m.From.ClientList().Scan(&clientList); err != nil {
panic(err)
log.Fatalf("failed to list clients with error %v\n", err)
}
for _, client := range clientList {
if client.Flags == "S" {
Expand All @@ -75,10 +75,10 @@ func (m *redisMigrator) waitForComplete() {

func (m *redisMigrator) onComplete() {
if err := m.To.SlaveOf("no", "one").Err(); err != nil {
panic(err)
log.Fatalf("failed to make target slave of no one with error %v\n", err)
}
if err := m.To.ConfigSet("slave-read-only", "no").Err(); err != nil {
panic(err)
log.Fatalf("failed to make target not slave-read-only with error %v\n", err)
}
}

Expand Down

0 comments on commit db1fcb5

Please sign in to comment.