utils

package
v0.0.0-...-ced8162 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplayString = "string"
	ReplayInt64s = "int64s"
)
View Source
const (
	GolangSecurityTime = "2006-01-02T15:04:05Z"
	// GolangSecurityTime = "2006-01-02 15:04:05"
	ReaderBufferSize = bytesize.MB * 32
	WriterBufferSize = bytesize.MB * 8

	LogLevelNone  = "none"
	LogLevelError = "error"
	LogLevelWarn  = "warn"
	LogLevelInfo  = "info"
	LogLevelDebug = "debug"
	LogLevelAll   = "all"

	TencentCluster = "tencent_cluster"
	AliyunCluster  = "aliyun_cluster"
	UCloudCluster  = "ucloud_cluster"
	CodisCluster   = "codis_cluster"

	CoidsErrMsg = "ERR backend server 'server' not found"
)
View Source
const (
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
	PB = 1024 * TB
)
View Source
const (
	AddressSplitter        = "@"
	AddressHeaderSplitter  = ":"
	AddressClusterSplitter = ";"
)

Variables

View Source
var (
	Version          = "$"
	LogRotater       *logRotate.Logger
	StartTime        string
	TargetRoundRobin int
	RDBVersion       uint = 9 // 9 for 5.0
)
View Source
var (
	HttpApi *nimo.HttpRestProvider
)
View Source
var (
	RecvChanSize = 4096
)

Functions

func AuthPassword

func AuthPassword(c net.Conn, auth_type, passwd string)

func Bytes2String

func Bytes2String(b []byte) string

func CheckHandleNetError

func CheckHandleNetError(err error) bool

func CheckVersionChecksum

func CheckVersionChecksum(d []byte) (uint, uint64, error)

func CompareVersion

func CompareVersion(a, b string, level int) int

* compare the version with given level. e.g., * 2.0.1, 2.0.3, level = 2 => equal: 0 * 2.0.1, 2.0.3, level = 3 => smaller: 1 * 3.1.1, 2.1 level = 2 => bigger: 2 * 3, 3.2, level = 2 => smaller: 1 * 3.a, 3.2, level = 2 => unknown: 3

func CutRedisInfoSegment

func CutRedisInfoSegment(content []byte, field string) []byte

cut segment

func Float64ToByte

func Float64ToByte(float float64) string

func FlushWriter

func FlushWriter(w *bufio.Writer)

func GetAllClusterNode

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

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

func GetFakeSlaveOffset

func GetFakeSlaveOffset(c redigo.Conn) (string, error)

func GetLocalIp

func GetLocalIp(preferdInterfaces []string) (ip string, interfaceName string, err error)

func GetMetric

func GetMetric(input int64) string

func GetRDBChecksum

func GetRDBChecksum(target, authType, auth string, tlsEnable bool) (string, error)

func GetReadableRedisAddressThroughSentinel

func GetReadableRedisAddressThroughSentinel(sentinelAddrs []string, sentinelMasterName string, fromMaster bool) (string, error)

GetReadableRedisAddressThroughSentinel gets readable redis address First, the function will pick one from available slaves randomly. If there is no available slave, it will pick master.

func GetRedisVersion

func GetRedisVersion(target, authType, auth string, tlsEnable bool) (string, error)
func GetTotalLink() int

func GetWritableRedisAddressThroughSentinel

func GetWritableRedisAddressThroughSentinel(sentinelAddrs []string, sentinelMasterName string) (string, error)

getWritableRedisAddressThroughSentinel gets writable redis address The function will return redis master address.

func Goodbye

func Goodbye()

func InitHttpApi

func InitHttpApi(port int)

func Iocopy

func Iocopy(r io.Reader, w io.Writer, p []byte, max int) int

func KeyToSlot

func KeyToSlot(key string) uint16

func NewClusterConn

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

func NewRDBLoader

func NewRDBLoader(reader *bufio.Reader, rbytes *atomic2.Int64, size int) chan *rdb.BinEntry

func OpenNetConn

func OpenNetConn(target, auth_type, passwd string, tlsEnable bool) net.Conn

func OpenNetConnSoft

func OpenNetConnSoft(target, auth_type, passwd string, tlsEnable bool) net.Conn

func OpenReadFile

func OpenReadFile(name string) (*os.File, int64)

func OpenReadWriteFile

func OpenReadWriteFile(name string) *os.File

func OpenRedisConn

func OpenRedisConn(target []string, auth_type, passwd string, isCluster bool, tlsEnable bool) redigo.Conn

func OpenRedisConnWithTimeout

func OpenRedisConnWithTimeout(target []string, auth_type, passwd string, readTimeout, writeTimeout time.Duration,
	isCluster bool, tlsEnable bool) redigo.Conn

func OpenSyncConn

func OpenSyncConn(target string, auth_type, passwd string, tlsEnable bool) (net.Conn, <-chan int64)

func OpenWriteFile

func OpenWriteFile(name string) *os.File

func ParseAddress

func ParseAddress(tp string) error

parse source address and target address

func ParseInfo

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

func ParseKeyspace

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

func ParseRedisInfo

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

parse single info field: "info server", "info keyspace"

func PickTargetRoundRobin

func PickTargetRoundRobin(n int) int

func ReadRESPEnd

func ReadRESPEnd(c net.Conn) (string, error)

read until hit the end of RESP: "\r\n"

func RemoveRESPEnd

func RemoveRESPEnd(input string) string

func RestoreBigkey

func RestoreBigkey(client redigo.Conn, key string, value string, pttl int64, db int, preDb *int)

func RestoreRdbEntry

func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry)

func SelectDB

func SelectDB(c redigo.Conn, db uint32)

func SendPSyncAck

func SendPSyncAck(bw *bufio.Writer, offset int64) error

func SendPSyncContinue

func SendPSyncContinue(br *bufio.Reader, bw *bufio.Writer, runid string, offset int64)

func SendPSyncFullsync

func SendPSyncFullsync(br *bufio.Reader, bw *bufio.Writer) (string, int64, <-chan int64)

func SendPSyncListeningPort

func SendPSyncListeningPort(c net.Conn, port int)

func StartQoS

func StartQoS(limit int) chan struct{}

func String2Bytes

func String2Bytes(s string) []byte

func Welcome

func Welcome()

func WritePid

func WritePid(id string) (err error)

func WritePidById

func WritePidById(id string, path string) error

Types

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

Jump to

Keyboard shortcuts

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