common

package
v0.0.0-...-5b294ad Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetryCount     = 20 // client attribute
	StatRollFrequency = 2  // client attribute

	TypeChanged int64 = -1 // marks the given key type is change, e.g. from string to list

	// db type
	TypeDB           = 0 // db
	TypeCluster      = 1
	TypeAliyunProxy  = 2 // aliyun proxy
	TypeTencentProxy = 3 // tencent cloud proxy

	TypeMaster = "master"
	TypeSlave  = "slave"
	TypeAll    = "all"

	Splitter = ";"
)
View Source
const (
	RecvChanSize = 4096
)
View Source
const (
	Star = byte('*')
)

Variables

View Source
var (
	BigKeyThreshold int64 = 16384
	Logger          seelog.LoggerInterface
)
View Source
var EndKeyType = &KeyType{
	Name:            "unknown",
	Index:           EndKeyTypeIndex,
	FetchLenCommand: "unknown",
}
View Source
var HashKeyType = &KeyType{
	Name:            "hash",
	Index:           HashTypeIndex,
	FetchLenCommand: "hlen",
}
View Source
var ListKeyType = &KeyType{
	Name:            "list",
	Index:           ListTypeIndex,
	FetchLenCommand: "llen",
}
View Source
var NoneKeyType = &KeyType{
	Name:            "none",
	Index:           NoneTypeIndex,
	FetchLenCommand: "strlen",
}
View Source
var SetKeyType = &KeyType{
	Name:            "set",
	Index:           SetTypeIndex,
	FetchLenCommand: "scard",
}
View Source
var StreamKeyType = &KeyType{
	Name:            "stream",
	Index:           StreamTypeIndex,
	FetchLenCommand: "xlen",
}
View Source
var StringKeyType = &KeyType{
	Name:            "string",
	Index:           StringTypeIndex,
	FetchLenCommand: "strlen",
}
View Source
var ZsetKeyType = &KeyType{
	Name:            "zset",
	Index:           ZsetTypeIndex,
	FetchLenCommand: "zcard",
}

Functions

func CheckFilter

func CheckFilter(filterTree *Trie, keyBytes []byte) bool

* @Vinllen Chen. check filter hit the key. * return: true/false. true means pass. * Actually, it's better to use trie tree instead of for-loop brute way. The reason I choose this is because * input filterList is not long in general, and I'm a lazy guy~.

func CompareUnorderedList

func CompareUnorderedList(a, b []string) bool

compare two unordered list. return true means equal.

func FilterDBList

func FilterDBList(dbs string) map[int]struct{}

func GetAllClusterNode

func GetAllClusterNode(client redigo.Conn, role string, choose string) ([]string, error)

return id list if choose == "id", otherwise address

func HandleLogLevel

func HandleLogLevel(logLevel string) (string, error)

func InitLog

func InitLog(logFile string, logLevel string) (seelog.LoggerInterface, error)

func Min

func Min(a, b int) int

func NewClusterConn

func NewClusterConn(clusterClient *redigoCluster.Cluster, recvChanSize int) redigo.Conn

func ParseInfo

func ParseInfo(content []byte) map[string]string

ParseInfo convert result of info command to map[string]string. For example, "opapply_source_count:1\r\nopapply_source_0:server_id=3171317,applied_opid=1\r\n" is converted to map[string]string{"opapply_source_count": "1", "opapply_source_0": "server_id=3171317,applied_opid=1"}.

func ParseKeyspace

func ParseKeyspace(content []byte) (map[int32]int64, error)

func ValueHelper_Hash_SortedSet

func ValueHelper_Hash_SortedSet(reply interface{}) map[string][]byte

func ValueHelper_List

func ValueHelper_List(reply interface{}) [][]byte

func ValueHelper_Set

func ValueHelper_Set(reply interface{}) map[string][]byte

Types

type Attribute

type Attribute struct {
	ItemCount int64 // the length of value
}

type ClusterConn

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

implement redigo.Conn(https://github.com/garyburd/redigo) * Embed redis-go-cluster(https://github.com/chasex/redis-go-cluster) * The reason I create this struct is that redis-go-cluster isn't fulfill redigo.Conn * interface. So I implement "Err", "Send", "Flush" and "Receive" interfaces.

func (*ClusterConn) Close

func (cc *ClusterConn) Close() error

func (*ClusterConn) Do

func (cc *ClusterConn) Do(commandName string, args ...interface{}) (reply interface{}, err error)

func (*ClusterConn) Err

func (cc *ClusterConn) Err() error

func (*ClusterConn) Flush

func (cc *ClusterConn) Flush() error

send batcher and put the return into recvChan

func (*ClusterConn) Receive

func (cc *ClusterConn) Receive() (reply interface{}, err error)

read recvChan

func (*ClusterConn) Send

func (cc *ClusterConn) Send(commandName string, args ...interface{}) error

just add into batcher

type ClusterNodeInfo

type ClusterNodeInfo struct {
	Id          string
	Address     string
	Flags       string
	Master      string
	PingSent    string
	PongRecv    string
	ConfigEpoch string
	LinkStat    string
	Slot        string
}

func ClusterNodeChoose

func ClusterNodeChoose(input []*ClusterNodeInfo, role string) []*ClusterNodeInfo

needMaster: true(master), false(slave)

func ParseClusterNode

func ParseClusterNode(content []byte) []*ClusterNodeInfo

* 10.1.1.1:21331> cluster nodes * d49a4c7b516b8da222d46a0a589b77f381285977 10.1.1.1:21333@31333 master - 0 1557996786000 3 connected 10923-16383 * f23ba7be501b2dcd4d6eeabd2d25551513e5c186 10.1.1.1:21336@31336 slave d49a4c7b516b8da222d46a0a589b77f381285977 0 1557996785000 6 connected * 75fffcd521738606a919607a7ddd52bcd6d65aa8 10.1.1.1:21331@31331 myself,master - 0 1557996784000 1 connected 0-5460 * da3dd51bb9cb5803d99942e0f875bc5f36dc3d10 10.1.1.1:21332@31332 master - 0 1557996786260 2 connected 5461-10922 * eff4e654d3cc361a8ec63640812e394a8deac3d6 10.1.1.1:21335@31335 slave da3dd51bb9cb5803d99942e0f875bc5f36dc3d10 0 1557996787261 5 connected * 486e081f8d47968df6a7e43ef9d3ba93b77d03b2 10.1.1.1:21334@31334 slave 75fffcd521738606a919607a7ddd52bcd6d65aa8 0 1557996785258 4 connected

type ConflictType

type ConflictType int
const (
	TypeConflict ConflictType = iota
	ValueConflict
	LackSourceConflict
	LackTargetConflict
	NoneConflict
	EndConflict
)

func NewConflictType

func NewConflictType(a string) ConflictType

func (ConflictType) String

func (p ConflictType) String() string

type Field

type Field struct {
	Field        []byte
	ConflictType ConflictType
}

type Key

type Key struct {
	Key          []byte
	Db           int32
	Tp           *KeyType
	ConflictType ConflictType
	SourceAttr   Attribute
	TargetAttr   Attribute

	Field []Field
}

type KeyType

type KeyType struct {
	Name            string // type
	Index           KeyTypeIndex
	FetchLenCommand string
}

func NewKeyType

func NewKeyType(a string) *KeyType

func (KeyType) String

func (p KeyType) String() string

type KeyTypeIndex

type KeyTypeIndex int
const (
	StringTypeIndex KeyTypeIndex = iota
	HashTypeIndex
	ListTypeIndex
	SetTypeIndex
	ZsetTypeIndex
	StreamTypeIndex
	NoneTypeIndex
	EndKeyTypeIndex
)

func (KeyTypeIndex) String

func (p KeyTypeIndex) String() string

type Qos

type Qos struct {
	Bucket chan struct{}
	// contains filtered or unexported fields
}

func StartQoS

func StartQoS(limit int) *Qos

func (*Qos) Close

func (q *Qos) Close()

type Trie

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

func NewTrie

func NewTrie() *Trie

func (*Trie) Insert

func (trie *Trie) Insert(word []byte)

func (*Trie) Search

func (trie *Trie) Search(word []byte) bool

type TrieNode

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

Jump to

Keyboard shortcuts

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