mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 09:17:10 +08:00
recover master slave relationship after restart
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/lib/utils"
|
||||
"github.com/hdt3213/godis/redis/connection"
|
||||
"github.com/hdt3213/godis/redis/protocol"
|
||||
)
|
||||
|
||||
@@ -44,6 +48,19 @@ func (cluster *Cluster) LocalExecWithinLock(c redis.Connection, cmdLine [][]byte
|
||||
return cluster.db.ExecWithLock(c, cmdLine)
|
||||
}
|
||||
|
||||
func (cluster *Cluster) SlaveOf(master string) error {
|
||||
host, port, err := net.SplitHostPort(master)
|
||||
if err != nil {
|
||||
return errors.New("invalid master address")
|
||||
}
|
||||
c := connection.NewFakeConn()
|
||||
reply := cluster.db.Exec(c, utils.ToCmdLine("slaveof", host, port))
|
||||
if err := protocol.Try2ErrorReply(reply); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPartitionKey extract hashtag
|
||||
func GetPartitionKey(key string) string {
|
||||
beg := strings.Index(key, "{")
|
||||
|
Reference in New Issue
Block a user