Documentation ¶
Index ¶
- Constants
- Variables
- func CRC16(buf []byte) uint16
- func CmdAuthRequired(cmd *resp.Command) bool
- func CmdFlag(cmd *resp.Command) int
- func CmdReadAll(cmd *resp.Command) bool
- func CmdReadOnly(cmd *resp.Command) bool
- func CmdUnknown(cmd *resp.Command) bool
- func IsMultiCmd(cmd *resp.Command) (multiKey bool, numKeys int)
- func Key2Slot(key string) int
- func LocalIP() string
- func ParseRedirectInfo(msg string) (slot int, server string)
- type BackendServer
- type BackendServerPool
- type Dispatcher
- type MultiCmd
- type MultiCmdExec
- type PipelineRequest
- type PipelineResponse
- type PipelineResponseHeap
- type Proxy
- type RedisConn
- type ServerGroup
- type Session
- type SlotInfo
- type SlotTable
Constants ¶
const ( // write commands always go to master // read from master READ_PREFER_MASTER = iota // read from slave if possible READ_PREFER_SLAVE // read from slave in the same idc if possible READ_PREFER_SLAVE_IDC CLUSTER_NODES_FIELD_NUM_IP_PORT = 1 CLUSTER_NODES_FIELD_NUM_FLAGS = 2 // it must be larger than any FIELD index CLUSTER_NODES_FIELD_SPLIT_NUM = 4 )
const ( NumSlots = 16384 CLUSTER_SLOTS_START = 0 CLUSTER_SLOTS_END = 1 CLUSTER_SLOTS_SERVER_START = 2 )
const ( CMD_FLAG_READ = iota CMD_FLAG_READ_ALL CMD_FLAG_PROXY CMD_FLAG_UNKNOWN CMD_FLAG_GENERAL )
Variables ¶
var ( REDIS_CMD_CLUSTER_SLOTS *resp.Command REDIS_CMD_CLUSTER_NODES *resp.Command REDIS_CMD_READ_ONLY *resp.Command )
var ( OK = []byte("OK") MOVED = []byte("-MOVED") ASK = []byte("-ASK") ASK_CMD_BYTES = []byte("+ASKING\r\n") AUTH_CMD_ERR = []byte("ERR invalid password") UNKNOWN_CMD_ERR = []byte("ERR unknown command") ARGUMENTS_ERR = []byte("ERR wrong number of arguments") NOAUTH_ERR = []byte("NOAUTH Authentication required.") OK_DATA = &resp.Data{T: resp.T_SimpleString, String: OK} )
Functions ¶
func CRC16 ¶
CRC16 returns checksum for a given set of bytes based on the crc algorithm defined for hashing redis keys in a cluster setup
func CmdAuthRequired ¶
func CmdReadAll ¶
func CmdReadOnly ¶
func CmdUnknown ¶
func ParseRedirectInfo ¶
ParseRedirectInfo parse slot redirect information from MOVED and ASK Error
Types ¶
type BackendServer ¶
type BackendServer struct {
// contains filtered or unexported fields
}
func NewBackendServer ¶
func NewBackendServer(server string, redisConn *RedisConn) *BackendServer
func (*BackendServer) Close ¶
func (tr *BackendServer) Close() error
func (*BackendServer) Request ¶
func (tr *BackendServer) Request(req *PipelineRequest) (*PipelineResponse, error)
type BackendServerPool ¶ added in v1.1.0
type BackendServerPool struct {
// contains filtered or unexported fields
}
func NewBackendServerPool ¶ added in v1.1.0
func NewBackendServerPool(redisConn *RedisConn) *BackendServerPool
func (*BackendServerPool) Get ¶ added in v1.1.0
func (b *BackendServerPool) Get(server string) (*BackendServer, error)
func (*BackendServerPool) Init ¶ added in v1.1.0
func (b *BackendServerPool) Init(server string) (*connpool.Pool, error)
func (*BackendServerPool) Put ¶ added in v1.1.0
func (b *BackendServerPool) Put(server *BackendServer) error
func (*BackendServerPool) Reload ¶ added in v1.1.0
func (b *BackendServerPool) Reload(servers map[string]bool)
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func (*Dispatcher) InitSlotTable ¶
func (d *Dispatcher) InitSlotTable() error
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run()
func (*Dispatcher) TriggerReloadSlots ¶
func (d *Dispatcher) TriggerReloadSlots()
schedule a reload task this call is inherently throttled, so that multiple clients can call it at the same time and it will only actually occur once
type MultiCmd ¶
type MultiCmd struct {
// contains filtered or unexported fields
}
multi key cmd被拆分成numKeys个子请求按普通的pipeline request发送,最后在写出response时进行合并 当最后一个子请求的response到来时,整个multi key cmd完成,拼接最终response并写出
只要有一个子请求失败,都认定整个请求失败 多个子请求共享一个request sequence number
请求的失败包含两种类型:1、网络失败,比如读取超时,2,请求错误,比如本来该在A机器上,请求到了B机器上,表现为response type为error
func (*MultiCmd) CoalesceRsp ¶
func (mc *MultiCmd) CoalesceRsp() *PipelineResponse
func (*MultiCmd) OnSubCmdFinished ¶
func (mc *MultiCmd) OnSubCmdFinished(rsp *PipelineResponse)
type MultiCmdExec ¶
type MultiCmdExec struct {
// contains filtered or unexported fields
}
func NewMultiCmdExec ¶
func NewMultiCmdExec(session *Session) *MultiCmdExec
type PipelineRequest ¶
type PipelineRequest struct {
// contains filtered or unexported fields
}
type PipelineResponse ¶
type PipelineResponse struct {
// contains filtered or unexported fields
}
type PipelineResponseHeap ¶
type PipelineResponseHeap []*PipelineResponse
func (PipelineResponseHeap) Len ¶
func (h PipelineResponseHeap) Len() int
func (PipelineResponseHeap) Less ¶
func (h PipelineResponseHeap) Less(i, j int) bool
func (*PipelineResponseHeap) Pop ¶
func (h *PipelineResponseHeap) Pop() interface{}
func (*PipelineResponseHeap) Push ¶
func (h *PipelineResponseHeap) Push(x interface{})
func (PipelineResponseHeap) Swap ¶
func (h PipelineResponseHeap) Swap(i, j int)
func (PipelineResponseHeap) Top ¶
func (h PipelineResponseHeap) Top() *PipelineResponse
Peek will return the heap top element
type RedisConn ¶
type RedisConn struct {
// contains filtered or unexported fields
}
func NewRedisConn ¶
type ServerGroup ¶
type ServerGroup struct {
// contains filtered or unexported fields
}
ServerGroup根据cluster slots和ReadPrefer得出
type Session ¶
func (*Session) ReadingLoop ¶
func (s *Session) ReadingLoop()
func (*Session) Schedule ¶
func (s *Session) Schedule(req *PipelineRequest)
func (*Session) WritingLoop ¶
func (s *Session) WritingLoop()
WritingLoop consumes backQ and send response to client It close the connection to notify reader on error and continue loop until the reader has exited
type SlotInfo ¶
type SlotInfo struct {
// contains filtered or unexported fields
}
func NewSlotInfo ¶
type SlotTable ¶
type SlotTable struct {
// contains filtered or unexported fields
}
func NewSlotTable ¶
func NewSlotTable() *SlotTable