Files
redis-go/cluster/pubsub.go
finley bf7f628810 raft cluster
wip: raft does not care about migrating

wip: optimize code

wip: raft election

wip

wip: fix raft leader missing log entries

wip

fix a dead lock

batch set slot route

wip: raft persist

wip

refactor cluster suite

remove relay

rename relay2

refactor: allow customizing client factory

test raft

refactor re-balance

avoid errors caused by inconsistent status on follower nodes during raft commits

test raft election
2023-06-10 22:48:24 +08:00

36 lines
1.1 KiB
Go

package cluster
import (
"github.com/hdt3213/godis/interface/redis"
"github.com/hdt3213/godis/lib/logger"
"github.com/hdt3213/godis/redis/protocol"
)
const (
relayPublish = "publish_"
)
// Publish broadcasts msg to all peers in cluster when receive publish command from client
func Publish(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply {
var count int64 = 0
results := cluster.broadcast(c, modifyCmd(cmdLine, relayPublish))
for _, val := range results {
if errReply, ok := val.(protocol.ErrorReply); ok {
logger.Error("publish occurs error: " + errReply.Error())
} else if intReply, ok := val.(*protocol.IntReply); ok {
count += intReply.Code
}
}
return protocol.MakeIntReply(count)
}
// Subscribe puts the given connection into the given channel
func Subscribe(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
return cluster.db.Exec(c, args) // let local db.hub handle subscribe
}
// UnSubscribe removes the given connection from the given channel
func UnSubscribe(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
return cluster.db.Exec(c, args) // let local db.hub handle subscribe
}