func sendPSyncFullsync(br *bufio.Reader, bw *bufio.Writer) (string, int64, <-chan int64) { cmd := redis.NewCommand("psync", "?", -1) if err := redis.Encode(bw, cmd, true); err != nil { log.PanicError(err, "write psync command failed, fullsync") } r, err := redis.Decode(br) if err != nil { log.PanicError(err, "invalid psync response, fullsync") } if e, ok := r.(*redis.Error); ok { log.Panicf("invalid psync response, fullsync, %s", e.Value) } x, err := redis.AsString(r, nil) if err != nil { log.PanicError(err, "invalid psync response, fullsync") } xx := strings.Split(x, " ") if len(xx) != 3 || strings.ToLower(xx[0]) != "fullresync" { log.Panicf("invalid psync response = '%s', should be fullsync", x) } v, err := strconv.ParseInt(xx[2], 10, 64) if err != nil { log.PanicError(err, "parse psync offset failed") } runid, offset := xx[1], v-1 return runid, offset, waitRdbDump(br) }
func sendPSyncContinue(br *bufio.Reader, bw *bufio.Writer, runid string, offset int64) { cmd := redis.NewCommand("psync", runid, offset+2) if err := redis.Encode(bw, cmd, true); err != nil { log.PanicError(err, "write psync command failed, continue") } r, err := redis.Decode(br) if err != nil { log.PanicError(err, "invalid psync response, continue") } if e, ok := r.(*redis.Error); ok { log.Panicf("invalid psync response, continue, %s", e.Value) } x, err := redis.AsString(r, nil) if err != nil { log.PanicError(err, "invalid psync response, continue") } xx := strings.Split(x, " ") if len(xx) != 1 || strings.ToLower(xx[0]) != "continue" { log.Panicf("invalid psync response = '%s', should be continue", x) } }