mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
cluster test suite
This commit is contained in:
50
cluster/utils.go
Normal file
50
cluster/utils.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/redis/protocol"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ping(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Reply {
|
||||
return cluster.db.Exec(c, cmdLine)
|
||||
}
|
||||
|
||||
/*----- utils -------*/
|
||||
|
||||
func makeArgs(cmd string, args ...string) [][]byte {
|
||||
result := make([][]byte, len(args)+1)
|
||||
result[0] = []byte(cmd)
|
||||
for i, arg := range args {
|
||||
result[i+1] = []byte(arg)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// return node -> writeKeys
|
||||
func (cluster *Cluster) groupBy(keys []string) map[string][]string {
|
||||
result := make(map[string][]string)
|
||||
for _, key := range keys {
|
||||
peer := cluster.peerPicker.PickNode(key)
|
||||
group, ok := result[peer]
|
||||
if !ok {
|
||||
group = make([]string, 0)
|
||||
}
|
||||
group = append(group, key)
|
||||
result[peer] = group
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func execSelect(c redis.Connection, args [][]byte) redis.Reply {
|
||||
dbIndex, err := strconv.Atoi(string(args[1]))
|
||||
if err != nil {
|
||||
return protocol.MakeErrReply("ERR invalid DB index")
|
||||
}
|
||||
if dbIndex >= config.Properties.Databases {
|
||||
return protocol.MakeErrReply("ERR DB index is out of range")
|
||||
}
|
||||
c.SelectDB(dbIndex)
|
||||
return protocol.MakeOkReply()
|
||||
}
|
Reference in New Issue
Block a user