resp

package
v0.0.0-...-110c355 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INFO    string = "INFO"
	COMMAND string = "COMMAND"
	PING    string = "PING"
	PONG    string = "PONG"
	ECHO    string = "ECHO"
	TYPE    string = "TYPE"

	AUTH     string = "AUTH"
	SHUTDOWN string = "SHUTDOWN"

	PKSETEXAT string = "PKSETEXAT"

	SET         string = "SET"
	SETEX       string = "SETEX"
	PSETEX      string = "PSETEX"
	SETNX       string = "SETNX"
	MSET        string = "MSET"
	DEL         string = "DEL"
	GET         string = "GET"
	GETSET      string = "GETSET"
	MGET        string = "MGET"
	INCR        string = "INCR"
	INCRBY      string = "INCRBY"
	INCRBYFLOAT string = "INCRBYFLOAT"
	DECR        string = "DECR"
	DECRBY      string = "DECRBY"
	EXISTS      string = "EXISTS"
	EXPIRE      string = "EXPIRE"
	EXPIREAT    string = "EXPIREAT"
	PEXPIRE     string = "PEXPIRE"
	PEXPIREAT   string = "PEXPIREAT"
	TTL         string = "TTL"
	PTTL        string = "PTTL"
	PERSIST     string = "PERSIST"

	UNLINK string = "UNLINK"
	SELECT string = "SELECT"

	KDEL      string = "KDEL"
	KTTL      string = "KTTL"
	KEXISTS   string = "KEXISTS"
	KEXPIRE   string = "KEXPIRE"
	KPERSIST  string = "KPERSIST"
	KEXPIREAT string = "KEXPIREAT"

	APPEND   string = "APPEND"
	GETRANGE string = "GETRANGE"
	SETRANGE string = "SETRANGE"
	STRLEN   string = "STRLEN"

	BITCOUNT string = "BITCOUNT"
	BITPOS   string = "BITPOS"
	GETBIT   string = "GETBIT"
	SETBIT   string = "SETBIT"

	HSET    string = "HSET"
	HMSET   string = "HMSET"
	HGET    string = "HGET"
	HMGET   string = "HMGET"
	HEXISTS string = "HEXISTS"
	HLEN    string = "HLEN"
	HKEYS   string = "HKEYS"
	HVALS   string = "HVALS"
	HDEL    string = "HDEL"
	HINCRBY string = "HINCRBY"
	HGETALL string = "HGETALL"
	HSCAN   string = "HSCAN"

	HCLEAR     string = "HCLEAR"
	HEXPIRE    string = "HEXPIRE"
	HEXPIREAT  string = "HEXPIREAT"
	HTTL       string = "HTTL"
	HPERSIST   string = "HPERSIST"
	HKEYEXISTS string = "HKEYEXISTS"

	SADD        string = "SADD"
	SREM        string = "SREM"
	SPOP        string = "SPOP"
	SCARD       string = "SCARD"
	SISMEMBER   string = "SISMEMBER"
	SMEMBERS    string = "SMEMBERS"
	SSCAN       string = "SSCAN"
	SRANDMEMBER string = "SRANDMEMBER"

	SCLEAR     string = "SCLEAR"
	SEXPIRE    string = "SEXPIRE"
	SEXPIREAT  string = "SEXPIREAT"
	STTL       string = "STTL"
	SPERSIST   string = "SPERSIST"
	SKEYEXISTS string = "SKEYEXISTS"

	ZADD             string = "ZADD"
	ZSCORE           string = "ZSCORE"
	ZCARD            string = "ZCARD"
	ZCOUNT           string = "ZCOUNT"
	ZINCRBY          string = "ZINCRBY"
	ZRANGE           string = "ZRANGE"
	ZRANGEBYSCORE    string = "ZRANGEBYSCORE"
	ZREVRANGEBYSCORE string = "ZREVRANGEBYSCORE"
	ZRANK            string = "ZRANK"
	ZREM             string = "ZREM"
	ZREMRANGEBYRANK  string = "ZREMRANGEBYRANK"
	ZREMRANGEBYSCORE string = "ZREMRANGEBYSCORE"
	ZREVRANGE        string = "ZREVRANGE"
	ZREVRANK         string = "ZREVRANK"
	ZREMRANGEBYLEX   string = "ZREMRANGEBYLEX"
	ZLEXCOUNT        string = "ZLEXCOUNT"
	ZSCAN            string = "ZSCAN"

	ZCLEAR      string = "ZCLEAR"
	ZEXPIRE     string = "ZEXPIRE"
	ZEXPIREAT   string = "ZEXPIREAT"
	ZTTL        string = "ZTTL"
	ZPERSIST    string = "ZPERSIST"
	ZKEYEXISTS  string = "ZKEYEXISTS"
	ZRANGEBYLEX string = "ZRANGEBYLEX"

	LPUSH   string = "LPUSH"
	RPUSH   string = "RPUSH"
	LPOP    string = "LPOP"
	RPOP    string = "RPOP"
	LLEN    string = "LLEN"
	LINDEX  string = "LINDEX"
	LRANGE  string = "LRANGE"
	LREM    string = "LREM"
	LINSERT string = "LINSERT"
	LSET    string = "LSET"
	LTRIM   string = "LTRIM"
	LPUSHX  string = "LPUSHX"
	RPUSHX  string = "RPUSHX"

	LCLEAR     string = "LCLEAR"
	LMCLEAR    string = "LMCLEAR"
	LEXPIRE    string = "LEXPIRE"
	LEXPIREAT  string = "LEXPIREAT"
	LTTL       string = "LTTL"
	LPERSIST   string = "LPERSIST"
	LKEYEXISTS string = "LKEYEXISTS"
	LTRIMBACK  string = "LTRIM_BACK"
	LTRIMFRONT string = "LTRIM_FRONT"

	WATCH   string = "WATCH"
	UNWATCH string = "UNWATCH"
	MULTI   string = "MULTI"
	EXEC    string = "EXEC"
	PREPARE string = "PREPARE"
	DISCARD string = "DISCARD"

	EVAL    string = "EVAL"
	SCRIPT  string = "SCRIPT"
	EVALSHA string = "EVALSHA"

	GEOADD            string = "GEOADD"
	GEODIST           string = "GEODIST"
	GEOPOS            string = "GEOPOS"
	GEOHASH           string = "GEOHASH"
	GEORADIUS         string = "GEORADIUS"
	GEORADIUSBYMEMBER string = "GEORADIUSBYMEMBER"
)
View Source
const (
	RangeClose uint8 = 0x00
	RangeLopen uint8 = 0x01
	RangeRopen uint8 = 0x10
)
View Source
const (
	TagBeg = '{'
	TagEnd = '}'
)
View Source
const (
	TxStateNone   int = 0
	TxStateWatch  int = 0x1
	TxStateCancel int = 0x10
)
View Source
const (
	DefaultCmdType uint8 = 0
	MgetCmdType    uint8 = 1
	MsetCmdType    uint8 = 2
	DelCmdType     uint8 = 3
)
View Source
const (
	TxCommandNumLimit = 100
)

Variables

View Source
var (
	EmptyCommandErr           = errors.New("empty command")
	NotFoundErr               = errors.New("command not found")
	NotImplementErr           = errors.New("command not implement")
	NotAuthenticatedErr       = errors.New("not authenticated")
	AuthenticationFailureErr  = errors.New("authentication failure")
	WriteErrorOnReadOnlyProxy = errors.New("Proxy Support READ COMMAND ONLY")
	RangeOffsetErr            = errors.New("ERR offset is out of range")
	BitOffsetErr              = errors.New("ERR bit offset is not an integer or out of range")
	SyntaxErr                 = errors.New("ERR syntax error")
	ValueErr                  = errors.New("ERR value is not an integer or out of range")
	FloatErr                  = errors.New("ERR value is not a valid float")
	HashTagErr                = errors.New("ERR hashtag mismatch or missing")
	TxGroupChangedErr         = errors.New("ERR group changed in tx")
	TxAbortErr                = errors.New("EXECABORT Transaction discarded because of previous errors.")
)
View Source
var (
	Delims = []byte("\r\n")

	NullBulk  = []byte("-1")
	NullArray = []byte("-1")

	ReplyOK     = "OK"
	ReplyPONG   = "PONG"
	ReplyQUEUED = "QUEUED"
)
View Source
var NoScanMember = []byte("0")

Functions

func CmdParamsErr

func CmdParamsErr(cmd string) error

func ExtractHashTag

func ExtractHashTag(key string) []byte

func Int64

func Int64(reply interface{}, err error) (int64, error)

func InterfaceByte

func InterfaceByte(items [][]byte) []interface{}

func InterfaceByteSubKeys

func InterfaceByteSubKeys(key []byte, fields [][]byte) []interface{}

func InterfaceString

func InterfaceString(items []string) []interface{}

func LowerSlice

func LowerSlice(buf []byte) []byte

func PackArgs

func PackArgs(items ...interface{}) (args []interface{})

func ParseSetArgs

func ParseSetArgs(args [][]byte) (e ExpireType, t int64, c SetCondition, err error)

func Register

func Register(name string, f CommandFunc)

func StringSlice

func StringSlice(b [][]byte) []string

func UpperSlice

func UpperSlice(buf []byte) []byte

Types

type Cmd

type Cmd struct {
	Name    string
	Handler func(c *Session) error
}

type CommandFunc

type CommandFunc func(c *Session) error

type Error

type Error string

func (Error) Error

func (err Error) Error() string

type ExpireType

type ExpireType string
const (
	EX     ExpireType = "EX"
	PX     ExpireType = "PX"
	NoType ExpireType = ""
)

type InternalServerConn

type InternalServerConn struct {
	GroupId  int
	Conn     redis.Conn
	HostPort string
}

type RespReader

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

func NewRespReader

func NewRespReader(conn net.Conn, size int) *RespReader

func (*RespReader) Parse

func (resp *RespReader) Parse() (interface{}, error)

func (*RespReader) ParseBulkTo

func (resp *RespReader) ParseBulkTo(w io.Writer) error

func (*RespReader) ParseRequest

func (resp *RespReader) ParseRequest() ([][]byte, error)

type RespWriter

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

func NewRespWriter

func NewRespWriter(conn net.Conn, size int) *RespWriter

func (*RespWriter) Flush

func (w *RespWriter) Flush()

func (*RespWriter) WriteArray

func (w *RespWriter) WriteArray(lst []interface{})

func (*RespWriter) WriteBulk

func (w *RespWriter) WriteBulk(b []byte)

func (*RespWriter) WriteBulkFrom

func (w *RespWriter) WriteBulkFrom(n int64, rb io.Reader)

func (*RespWriter) WriteError

func (w *RespWriter) WriteError(err error)

func (*RespWriter) WriteFVPairArray

func (w *RespWriter) WriteFVPairArray(lst [][]byte)

func (*RespWriter) WriteInteger

func (w *RespWriter) WriteInteger(n int64)

func (*RespWriter) WriteScorePairArray

func (w *RespWriter) WriteScorePairArray(lst [][]byte, withScores bool)

func (*RespWriter) WriteSliceArray

func (w *RespWriter) WriteSliceArray(lst [][]byte)

func (*RespWriter) WriteStatus

func (w *RespWriter) WriteStatus(status string)

type Session

type Session struct {
	Cmd  string
	Args [][]byte

	RespWriter *RespWriter
	RespReader *RespReader

	Stats *dostats.CalDoStats

	OpenDistributedTx bool
	TxState           int
	TxCommandQueued   bool
	Recorder          *TxRecorder
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn net.Conn, connReaderBufferSize int, connWriteBufferSize int, openDistributedTx bool) *Session

func (*Session) Close

func (s *Session) Close()

func (*Session) DoAuth

func (s *Session) DoAuth() error

func (*Session) GetTxClients

func (s *Session) GetTxClients() map[int]*InternalServerConn

func (*Session) IsAdmin

func (s *Session) IsAdmin() bool

func (*Session) Perform

func (s *Session) Perform(startUnixNano int64) error

func (*Session) ReleaseTxClients

func (s *Session) ReleaseTxClients()

func (*Session) ResetTx

func (s *Session) ResetTx()

func (*Session) SendTxQueued

func (s *Session) SendTxQueued(err error) error

func (*Session) SetAuth

func (s *Session) SetAuth(authEnabled bool, userPassword, adminPassword string)

func (*Session) SetLastQueryTime

func (s *Session) SetLastQueryTime()

func (*Session) SetQueryProperty

func (s *Session) SetQueryProperty(v bool)

func (*Session) SetReadDeadline

func (s *Session) SetReadDeadline()

func (*Session) SetTxCancel

func (s *Session) SetTxCancel(err error)

func (*Session) SetTxClients

func (s *Session) SetTxClients(clients map[int]*InternalServerConn)

type SessionManager

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

func NewSessionManager

func NewSessionManager() *SessionManager

func (*SessionManager) AddSession

func (m *SessionManager) AddSession(s *Session)

type SetCondition

type SetCondition string
const (
	NX          SetCondition = "NX"
	XX          SetCondition = "XX"
	NoCondition SetCondition = ""
)

type TxCommandServerMap

type TxCommandServerMap struct {
	Command       uint8
	KeyNum        int
	GroupId       int
	ServerRespSeq map[int]int
	RespGroupMap  map[int][]int
	Response      interface{}
}

type TxRecorder

type TxRecorder struct {
	CmdNum        int
	MultiOk       bool
	ServerClients map[int]*InternalServerConn
	ServerCmdNum  map[int]int
	TxCommands    []*TxCommandServerMap
}

func (*TxRecorder) AddCommand

func (tr *TxRecorder) AddCommand(gid int)

func (*TxRecorder) Reset

func (tr *TxRecorder) Reset()

Jump to

Keyboard shortcuts

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