mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 00:42:43 +08:00

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
95 lines
1.8 KiB
Go
95 lines
1.8 KiB
Go
package protocol
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/hdt3213/godis/interface/redis"
|
|
)
|
|
|
|
// PongReply is +PONG
|
|
type PongReply struct{}
|
|
|
|
var pongBytes = []byte("+PONG\r\n")
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *PongReply) ToBytes() []byte {
|
|
return pongBytes
|
|
}
|
|
|
|
// OkReply is +OK
|
|
type OkReply struct{}
|
|
|
|
var okBytes = []byte("+OK\r\n")
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *OkReply) ToBytes() []byte {
|
|
return okBytes
|
|
}
|
|
|
|
var theOkReply = new(OkReply)
|
|
|
|
// MakeOkReply returns a ok protocol
|
|
func MakeOkReply() *OkReply {
|
|
return theOkReply
|
|
}
|
|
|
|
var nullBulkBytes = []byte("$-1\r\n")
|
|
|
|
// NullBulkReply is empty string
|
|
type NullBulkReply struct{}
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *NullBulkReply) ToBytes() []byte {
|
|
return nullBulkBytes
|
|
}
|
|
|
|
// MakeNullBulkReply creates a new NullBulkReply
|
|
func MakeNullBulkReply() *NullBulkReply {
|
|
return &NullBulkReply{}
|
|
}
|
|
|
|
var emptyMultiBulkBytes = []byte("*0\r\n")
|
|
|
|
// EmptyMultiBulkReply is a empty list
|
|
type EmptyMultiBulkReply struct{}
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *EmptyMultiBulkReply) ToBytes() []byte {
|
|
return emptyMultiBulkBytes
|
|
}
|
|
|
|
// MakeEmptyMultiBulkReply creates EmptyMultiBulkReply
|
|
func MakeEmptyMultiBulkReply() *EmptyMultiBulkReply {
|
|
return &EmptyMultiBulkReply{}
|
|
}
|
|
|
|
func IsEmptyMultiBulkReply(reply redis.Reply) bool {
|
|
return bytes.Equal(reply.ToBytes(), emptyMultiBulkBytes)
|
|
}
|
|
|
|
// NoReply respond nothing, for commands like subscribe
|
|
type NoReply struct{}
|
|
|
|
var noBytes = []byte("")
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *NoReply) ToBytes() []byte {
|
|
return noBytes
|
|
}
|
|
|
|
// QueuedReply is +QUEUED
|
|
type QueuedReply struct{}
|
|
|
|
var queuedBytes = []byte("+QUEUED\r\n")
|
|
|
|
// ToBytes marshal redis.Reply
|
|
func (r *QueuedReply) ToBytes() []byte {
|
|
return queuedBytes
|
|
}
|
|
|
|
var theQueuedReply = new(QueuedReply)
|
|
|
|
// MakeQueuedReply returns a QUEUED protocol
|
|
func MakeQueuedReply() *QueuedReply {
|
|
return theQueuedReply
|
|
}
|