router

package
v0.0.0-...-de897e3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

对应RedisClient结构体, 及相应的功能

Index

Constants

View Source
const MaxSlotNum = models.DEFAULT_SLOT_NUM

Variables

View Source
var (
	ErrBadRespType = errors.New("bad resp type for command")
	ErrBadOpStrLen = errors.New("bad command length, too short or too long")
)
View Source
var ErrFailedRequest = errors.New("discard failed request")
View Source
var ErrRespIsRequired = errors.New("resp is required")
View Source
var ErrSlotIsNotReady = errors.New("slot is not ready, may be offline")

Functions

func OpCounts

func OpCounts() int64

Types

type BackendConn

type BackendConn struct {
	// contains filtered or unexported fields
}

如何实现的读写分离及 Request & Response 匹配的?

func NewBackendConn

func NewBackendConn(addr, auth string) *BackendConn

func (*BackendConn) Addr

func (bc *BackendConn) Addr() string

func (*BackendConn) Close

func (bc *BackendConn) Close()

func (*BackendConn) KeepAlive

func (bc *BackendConn) KeepAlive() bool

这个是?

func (*BackendConn) PushBack

func (bc *BackendConn) PushBack(r *Request)

func (*BackendConn) Run

func (bc *BackendConn) Run()

type Dispatcher

type Dispatcher interface {
	Dispatch(r *Request) error
}

type FlushPolicy

type FlushPolicy struct {
	*redis.Encoder

	MaxBuffered int
	MaxInterval int64
	// contains filtered or unexported fields
}

func (*FlushPolicy) Encode

func (p *FlushPolicy) Encode(resp *redis.Resp, force bool) error

func (*FlushPolicy) Flush

func (p *FlushPolicy) Flush(force bool) error

type OpStats

type OpStats struct {
	// contains filtered or unexported fields
}

func GetAllOpStats

func GetAllOpStats() []*OpStats

func GetOpStats

func GetOpStats(opstr string, create bool) *OpStats

func (*OpStats) Calls

func (s *OpStats) Calls() int64

func (*OpStats) MarshalJSON

func (s *OpStats) MarshalJSON() ([]byte, error)

func (*OpStats) OpStr

func (s *OpStats) OpStr() string

func (*OpStats) USecs

func (s *OpStats) USecs() int64

type Request

type Request struct {
	// 原始的请求串?
	OpStr string
	// 请求开始的时间戳?
	Start int64

	// 解析后的请求?
	Resp *redis.Resp

	Coalesce func() error
	// 处理结果
	Response struct {
		Resp *redis.Resp
		Err  error
	}

	// 这两个的区别?
	// future锁, writer 使用 r.Wait.Wait() 等待处理的结束.
	// 对象构造的时候会初始化, 见session.go handleRequest()
	Wait *sync.WaitGroup

	Failed *atomic2.Bool
	// contains filtered or unexported fields
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

slot-id -> slot-object

func New

func New() *Router

func NewWithAuth

func NewWithAuth(auth string) *Router

func (*Router) Close

func (s *Router) Close() error

func (*Router) Dispatch

func (s *Router) Dispatch(r *Request) error

这里应改写了r变量里的字段

func (*Router) FillSlot

func (s *Router) FillSlot(i int, addr, from string, lock bool) error

func (*Router) KeepAlive

func (s *Router) KeepAlive() error

func (*Router) ResetSlot

func (s *Router) ResetSlot(i int) error

type Session

type Session struct {
	*redis.Conn

	Ops int64

	// 上一条指令开始处理的时间
	LastOpUnix int64
	// 连接建立的时间
	CreateUnix int64
	// contains filtered or unexported fields
}

func NewSession

func NewSession(c net.Conn, auth string) *Session

func NewSessionSize

func NewSessionSize(c net.Conn, auth string, bufsize int, timeout int) *Session

func (*Session) Close

func (s *Session) Close() error

func (*Session) IsClosed

func (s *Session) IsClosed() bool

func (*Session) Serve

func (s *Session) Serve(d Dispatcher, maxPipeline int)

每个 client session 的伺服, goroutine 请求转发给后端都是在loopReader里处理的, loopWriter只是等待指令结果然后写回客户端

func (*Session) String

func (s *Session) String() string

type SharedBackendConn

type SharedBackendConn struct {
	*BackendConn
	// contains filtered or unexported fields
}

func NewSharedBackendConn

func NewSharedBackendConn(addr, auth string) *SharedBackendConn

func (*SharedBackendConn) Close

func (s *SharedBackendConn) Close() bool

func (*SharedBackendConn) IncrRefcnt

func (s *SharedBackendConn) IncrRefcnt()

type Slot

type Slot struct {
	// contains filtered or unexported fields
}

迁移过程中, 源redis-inst仅保存一个"ip:port"字符串, 没有分解出host/port 每个slot的请求都落到group-master上吗?

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL