func (R *RedMon) MakeMaster() bool {
	_, err := R.Client.SlaveOf("no", "one").Result()
	if err != nil {
		R.L.Printf("Error turning the slave to Master at IP:%s and port:%d", R.IP, R.Port)
		return false
	}
	R.L.Printf("Slave of NO ONE worked")
	return true
}
MakeMaster Make a Proc as a master (ie: supply the command "slaveof no on" to the Proc
package RedMon
import (
	"fmt"
	"io"
	"log"
	"strconv"
	"strings"
	"time"
	typ "github.com/mesos/mr-redis/common/types"
	"github.com/mesos/mr-redis/exec/docker"
	redisclient "gopkg.in/redis.v3"
)
type RedMon struct {
	P       *typ.Proc  
	Pid     int        
	IP      string     
	Port    int        
	Ofile   io.Writer  
	Efile   io.Writer  
	MS_Sync bool       
	MonChan chan int
	Container *docker.Dcontainer   
	Image     string               
	Client    *redisclient.Client  
	L         *log.Logger          
}
func NewRedMon(tskName string, IP string, Port int, data string, L *log.Logger, Image string) *RedMon {
	var R RedMon
	var P *typ.Proc
	R.MonChan = make(chan int)
	R.Port = Port
	R.IP = IP
	R.L = L
	R.L.Printf("Split data received is %v\n", data)
	splitData := strings.Split(data, " ")
	if len(splitData) < 1 || len(splitData) > 4 {
		R.L.Printf("RedMon Splitdata error %v\n", splitData)
		return nil
	}
	Cap, _ := strconv.Atoi(splitData[0])
	switch splitData[1] {
	case "Master":
		P = typ.NewProc(tskName, Cap, "M", "")
		R.L.Printf("created proc for new MASTER\n")
		break
	case "SlaveOf":
		P = typ.NewProc(tskName, Cap, "S", splitData[2])
		break
	case "Master-SlaveOf":
		P = typ.NewProc(tskName, Cap, "MS", splitData[2])
		R.MS_Sync = true
		break
	}
	R.P = P
	R.Container = &docker.Dcontainer{}
	R.Image = Image
	return &R
}
func (R *RedMon) getConnectedClient() *redisclient.Client {
	R.L.Printf("Monitoring stats")
	client := redisclient.NewClient(&redisclient.Options{
		Addr:     R.IP + ":" + fmt.Sprintf("%d", R.Port),
		Password: "",  
		DB:       0,   
	})
	pong, err := client.Ping().Result()
	R.L.Printf(pong, err)
	return client
}
func (R *RedMon) launchRedisServer(isSlave bool, IP string, port string) bool {
	var err error
	if isSlave {
		err = R.Container.Run(R.P.ID, R.Image, []string{"redis-server", fmt.Sprintf("--port %d", R.Port), fmt.Sprintf("--Slaveof %s %s", IP, port)}, int64(R.P.MemCap), R.P.ID+".log")
	} else {
		err = R.Container.Run(R.P.ID, R.Image, []string{"redis-server", fmt.Sprintf("--port %d", R.Port)}, int64(R.P.MemCap), R.P.ID+".log")
	}
	if err != nil {
		return false
	}
	time.Sleep(time.Second)
	R.Client = R.getConnectedClient()
	return true
}
func (R *RedMon) Start() bool {
	if R.P.SlaveOf == "" {
		return R.StartMaster()
	}
	if !R.MS_Sync {
		return R.StartSlave()
	}
	return R.StartSlaveAndMakeMaster()
}
func (R *RedMon) StartMaster() bool {
	var ret = false
	ret = R.launchRedisServer(false, "", "")
	if ret != true {
		return ret
	}
	R.Pid = 0
	R.P.Pid = 0
	R.P.Port = fmt.Sprintf("%d", R.Port)
	R.P.IP = R.IP
	R.P.State = "Running"
	R.P.Sync()
	return true
}
func (R *RedMon) StartSlave() bool {
	var ret = false
	slaveof := strings.Split(R.P.SlaveOf, ":")
	if len(slaveof) != 2 {
		R.L.Printf("Unacceptable SlaveOf value %vn", R.P.SlaveOf)
		return false
	}
	ret = R.launchRedisServer(true, slaveof[0], slaveof[1])
	if ret != true {
		return ret
	}
	for !R.IsSyncComplete() {
		time.Sleep(time.Second)
	}
	R.Pid = 0
	R.P.Pid = 0
	R.P.Port = fmt.Sprintf("%d", R.Port)
	R.P.IP = R.IP
	R.P.State = "Running"
	R.P.Sync()
	return true
}
func (R *RedMon) StartSlaveAndMakeMaster() bool {
	var ret = false
	slaveof := strings.Split(R.P.SlaveOf, ":")
	if len(slaveof) != 2 {
		R.L.Printf("Unacceptable SlaveOf value %vn", R.P.SlaveOf)
		return false
	}
	ret = R.launchRedisServer(true, slaveof[0], slaveof[1])
	if ret != true {
		return ret
	}
	R.Pid = 0
	for !R.IsSyncComplete() {
		time.Sleep(time.Second)
	}
	R.MakeMaster()
	R.Pid = 0
	R.P.Pid = 0
	R.P.Port = fmt.Sprintf("%d", R.Port)
	R.P.IP = R.IP
	R.P.State = "Running"
	R.P.Sync()
	return true
}
func fetchSubSection(value string, SubSection string) string {
	arr := strings.Split(value, "\r\n")
	for _, key := range arr {
		if strings.Contains(key, SubSection) {
			subArr := strings.Split(key, ":")
			if len(subArr) != 2 {
				return ""
			}
			return subArr[1]
		}
	}
	return ""
}
func (R *RedMon) GetRedisInfo(Section string, Subsection string) string {
	value, err := R.Client.Info(Section).Result()
	if err != nil {
		R.L.Printf("STATS collection returned error on IP:%s and PORT:%d Err:%v for section %s subsection %s", R.IP, R.Port, err, Section, Subsection)
		return ""
	}
	return fetchSubSection(value, Subsection)
}
func (R *RedMon) UpdateStats() bool {
	var redisStats typ.Stats
	var txt string
	var err error
	txt = R.GetRedisInfo("Memory", "used_memory")
	redisStats.Mem, err = strconv.ParseInt(txt, 10, 64)
	if err != nil {
		R.L.Printf("UpdateStats(Mem) Unable to convert %s to number %v", txt, err)
	}
	txt = R.GetRedisInfo("Server", "uptime_in_seconds")
	redisStats.Uptime, err = strconv.ParseInt(txt, 10, 64)
	if err != nil {
		R.L.Printf("UpdateStats(Uptime) Uptime Unable to convert %s to number %v", txt, err)
	}
	txt = R.GetRedisInfo("Clients", "connected_clients")
	redisStats.Clients, err = strconv.Atoi(txt)
	if err != nil {
		R.L.Printf("UpdateStats(Clients) Unable to convert %s to number %v", txt, err)
	}
	txt = R.GetRedisInfo("Replication", "master_last_io_seconds_ago")
	redisStats.LastSyced, err = strconv.Atoi(txt)
	if err != nil && txt != "" {
		R.L.Printf("UpdateStats(master_last_io) Unable to convert %s to number %v", txt, err)
	}
	txt = R.GetRedisInfo("Replication", "slave_repl_offset")
	redisStats.SlaveOffset, err = strconv.ParseInt(txt, 10, 64)
	if err != nil && txt != "" {
		R.L.Printf("UpdateStats(slave_repl_offset) Unable to convert %s to number %v", txt, err)
	}
	txt = R.GetRedisInfo("Replication", "slave_priority")
	redisStats.SlavePriority, err = strconv.Atoi(txt)
	if err != nil && txt != "" {
		R.L.Printf("UpdateStats(slave_priority) Unable to convert %s to number %v", txt, err)
	}
	errSync := R.P.SyncStats(redisStats)
	if !errSync {
		R.L.Printf("Error syncing stats to store")
		return false
	}
	return true
}
func (R *RedMon) Monitor() bool {
	CheckMsgCh := time.After(time.Second)
	UpdateStatsCh := time.After(2 * time.Second)
	for {
		if R.P.State == "Running" {
			select {
			case <-R.MonChan:
				R.L.Printf("Stopping RedMon for %s %s", R.P.IP, R.P.Port)
				return false
			case <-CheckMsgCh:
				R.CheckMsg()
				CheckMsgCh = time.After(time.Second)
			case <-UpdateStatsCh:
				R.UpdateStats()
				UpdateStatsCh = time.After(2 * time.Second)
			}
		} else {
			time.Sleep(time.Second)
		}
	}
}
func (R *RedMon) Stop() bool {
	_, err := R.Client.Shutdown().Result()
	if err != nil {
		R.L.Printf("problem shutting down the server at IP:%s and port:%d with error %v", R.IP, R.Port, err)
		errMsg := R.Die()
		if !errMsg {  
			R.L.Printf("Killing the redis server also did not work for  IP:%s and port:%d", R.IP, R.Port)
		}
		return false
	}
	return true
}
func (R *RedMon) Die() bool {
	err := R.Container.Kill()
	if err != nil {
		R.L.Printf("Unable to kill the process %v", err)
		return false
	}
	return true
}
func (R *RedMon) CheckMsg() {
	err := R.P.LoadMsg()
	if !err {
		R.L.Printf("Failed While Loading msg for proc %v from node %v", R.P.ID, R.P.Nodename)
		return
	}
	switch {
	case R.P.Msg == "SHUTDOWN":
		err = R.Stop()
		if err {
			R.L.Printf("failed to stop the REDIS server")
		}
		R.MonChan <- 1
		return
	case R.P.Msg == "MASTER":
		R.MakeMaster()
	case strings.Contains(R.P.Msg, "SLAVEOF"):
		R.TargetNewMaster(R.P.Msg)
	}
	R.P.Msg = ""
	R.P.SyncMsg()
}
func (R *RedMon) IsSyncComplete() bool {
	if R.Client == nil {
		return false
	}
	respStr, err := R.Client.Info("replication").Result()
	if err != nil {
		R.L.Printf("getting the repication stats from server at IP:%s and port:%d", R.IP, R.Port)
	}
	respArr := strings.Split(respStr, "\n")
	for _, resp := range respArr {
		R.L.Printf("resp = %v", resp)
		r := strings.Split(resp, ":")
		switch r[0] {
		case "role":
			if !strings.Contains(r[1], "slave") {
				R.L.Printf("Trying to call is sync, but this server is not really a slave IP:%s, port:%d", R.IP, R.Port)
				return false
			}
			continue
		case "master_sync_in_progress":
			if !strings.Contains(r[1], "0") {
				R.L.Printf("Sync not complete yet in slave IP:%s, port:%d", R.IP, R.Port)
				return false
			}
			return true
		case "master_sync_last_io_seconds_ago":
			return true
		default:
			continue
		}
	}
	return false
}