Documentation ¶
Index ¶
- Constants
- Variables
- func AuthPassword(c net.Conn, authType, passwd string)
- func Bool(reply interface{}, err error) (bool, error)
- func Bytes(reply interface{}, err error) ([]byte, error)
- func Bytes2String(b []byte) string
- func CheckFcv(file string, fcv int) (int, error)
- func CheckHandleNetError(err error) bool
- func CheckSlotDistributionEqual(src, dst []SlotOwner) bool
- func CheckVersionChecksum(d []byte) (uint, uint64, error)
- func ChoseSlotInRange(prefix string, left, right int) string
- func CompareUnorderedList(a, b []string) bool
- func CompareVersion(a, b string, level int) int
- func CutRedisInfoSegment(content []byte, field string) []byte
- func Float64(reply interface{}, err error) (float64, error)
- func Float64ToByte(float float64) string
- func FlushWriter(w *bufio.Writer)
- func GetAllClusterNode(client redigo.Conn, role string, choose string) ([]string, error)
- func GetFakeSlaveOffset(c redigo.Conn) (string, error)
- func GetLocalIp(preferdInterfaces []string) (ip string, interfaceName string, err error)
- func GetMetric(input int64) string
- func GetRDBChecksum(target, authType, auth string, tlsEnable bool) (string, error)
- func GetReadableRedisAddressThroughSentinel(sentinelAddrs []string, sentinelMasterName string, fromMaster bool) (string, error)
- func GetRedisVersion(target, authType, auth string, tlsEnable bool) (string, error)
- func GetSlotBoundary(shardList []SlotOwner, address string) (int, int)
- func GetTotalLink() int
- func GetWritableRedisAddressThroughSentinel(sentinelAddrs []string, sentinelMasterName string) (string, error)
- func Goodbye()
- func InitHttpApi(port int)
- func Int(reply interface{}, err error) (int, error)
- func Int64(reply interface{}, err error) (int64, error)
- func Iocopy(r io.Reader, w io.Writer, p []byte, max int) int
- func KeyToSlot(key string) uint16
- func MultiBulk(reply interface{}, err error) ([]interface{}, error)deprecated
- func NewClusterConn(clusterClient *redigoCluster.Cluster, recvChanSize int) redigo.Conn
- func NewRDBLoader(reader *bufio.Reader, rbytes *atomic2.Int64, size int) chan *rdb.BinEntry
- func OpenNetConn(target, authType, passwd string, tlsEnable bool) net.Conn
- func OpenNetConnSoft(target, authType, passwd string, tlsEnable bool) net.Conn
- func OpenReadFile(name string) (*os.File, int64)
- func OpenReadWriteFile(name string) *os.File
- func OpenRedisConn(target []string, authType, passwd string, isCluster bool, tlsEnable bool) redigo.Conn
- func OpenRedisConnWithTimeout(target []string, authType, passwd string, ...) redigo.Conn
- func OpenSyncConn(target string, authType, passwd string, tlsEnable bool) (net.Conn, <-chan int64)
- func OpenWriteFile(name string) *os.File
- func ParseAddress(tp string) error
- func ParseInfo(content []byte) map[string]string
- func ParseKeyspace(content []byte) (map[int32]int64, error)
- func ParseRedisInfo(content []byte) map[string]string
- func PickTargetRoundRobin(n int) int
- func ReadRESPEnd(c net.Conn) (string, error)
- func RemoveRESPEnd(input string) string
- func RestoreBigkey(client redigo.Conn, key string, value string, pttl int64, db int, preDb *int)
- func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry)
- func SelectDB(c redigo.Conn, db uint32)
- func SendPSyncAck(bw *bufio.Writer, offset int64) error
- func SendPSyncContinue(br *bufio.Reader, bw *bufio.Writer, runid string, offset int64) (string, int64, <-chan int64)
- func SendPSyncFullsync(br *bufio.Reader, bw *bufio.Writer) (string, int64, <-chan int64)
- func SendPSyncListeningPort(c net.Conn, port int)
- func StartQoS(limit int) chan struct{}
- func String(reply interface{}, err error) (string, error)
- func String2Bytes(s string) []byte
- func Uint64(reply interface{}, err error) (uint64, error)
- func Values(reply interface{}, err error) ([]interface{}, error)
- func Welcome()
- func WritePid(id string) (err error)
- func WritePidById(id string, path string) error
- type Checkpoint
- type ClusterConn
- func (cc *ClusterConn) Close() error
- func (cc *ClusterConn) Do(commandName string, args ...interface{}) (reply interface{}, err error)
- func (cc *ClusterConn) Err() error
- func (cc *ClusterConn) Flush() error
- func (cc *ClusterConn) Receive() (reply interface{}, err error)
- func (cc *ClusterConn) Send(commandName string, args ...interface{}) error
- type ClusterNodeInfo
- type Configuration
- type Error
- type Fcv
- type SlotOwner
Constants ¶
const ( ReplayString = "string" ReplayInt64s = "int64s" )
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" TencentCluster = "tencent_cluster" AliyunCluster = "aliyun_cluster" UCloudCluster = "ucloud_cluster" CodisCluster = "codis_cluster" CoidsErrMsg = "ERR backend server 'server' not found" CheckpointKey = "redis-shake-checkpoint" CheckpointOffset = "offset" CheckpointRunId = "runid" CheckpointVersion = "version" )
const ( KB = 1024 MB = 1024 * KB GB = 1024 * MB TB = 1024 * GB PB = 1024 * TB )
const ( AddressSplitter = "@" AddressHeaderSplitter = ":" AddressClusterSplitter = ";" )
Variables ¶
var ( Version = "$" LogRotater *logRotate.Logger StartTime string TargetRoundRobin int RDBVersion uint = 9 // 9 for 5.0 )
var ( FcvCheckpoint = Checkpoint{ CurrentVersion: 1, FeatureCompatibleVersion: 1, } FcvConfiguration = Configuration{ CurrentVersion: 1, FeatureCompatibleVersion: 0, } LowestCheckpointVersion = map[int]string{ 0: "1.0.0", 1: "2.0.0", } LowestConfigurationVersion = map[int]string{ 0: "1.0.0", 1: "2.0.0", } )
var ErrNil = errors.New("redigo: nil returned")
ErrNil indicates that a reply value is nil.
var (
HttpApi *nimo.HttpRestProvider
)
var (
RecvChanSize = 4096
)
Functions ¶
func AuthPassword ¶
func Bool ¶
Bool is a helper that converts a command reply to a boolean. If err is not equal to nil, then Bool returns false, err. Otherwise Bool converts the reply to boolean as follows:
Reply type Result integer value != 0, nil bulk string strconv.ParseBool(reply) nil false, ErrNil other false, error
func Bytes ¶
Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:
Reply type Result bulk string reply, nil simple string []byte(reply), nil nil nil, ErrNil other nil, error
func Bytes2String ¶
func CheckHandleNetError ¶
func ChoseSlotInRange ¶
chose key(${prefix}-${suffix}) to let it hash in the given slot boundary: [left, right]. return suffix
func CompareUnorderedList ¶
compare two unordered list. return true means equal.
func CompareVersion ¶
* 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 ¶
cut segment
func Float64 ¶
Float64 is a helper that converts a command reply to 64 bit float. If err is not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts the reply to an int as follows:
Reply type Result bulk string parsed reply, nil nil 0, ErrNil other 0, error
func Float64ToByte ¶
func FlushWriter ¶
func GetAllClusterNode ¶
return id list if choose == "id", otherwise address
func GetLocalIp ¶
func GetRDBChecksum ¶
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 GetSlotBoundary ¶
return -1, -1 means not found
func GetTotalLink ¶
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 InitHttpApi ¶
func InitHttpApi(port int)
func Int ¶
Int is a helper that converts a command reply to an integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int converts the reply to an int as follows:
Reply type Result integer int(reply), nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
func Int64 ¶
Int64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:
Reply type Result integer reply, nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
func NewClusterConn ¶
func NewClusterConn(clusterClient *redigoCluster.Cluster, recvChanSize int) redigo.Conn
func NewRDBLoader ¶
func OpenNetConnSoft ¶
func OpenReadWriteFile ¶
func OpenRedisConn ¶
func OpenSyncConn ¶
func OpenWriteFile ¶
func ParseRedisInfo ¶
parse single info field: "info server", "info keyspace"
func PickTargetRoundRobin ¶
func ReadRESPEnd ¶
read until hit the end of RESP: "\r\n"
func RemoveRESPEnd ¶
func RestoreBigkey ¶
func SendPSyncContinue ¶
func SendPSyncFullsync ¶
func SendPSyncListeningPort ¶
func String ¶
String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:
Reply type Result bulk string string(reply), nil simple string reply, nil nil "", ErrNil other "", error
func String2Bytes ¶
func Uint64 ¶
Uint64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:
Reply type Result integer reply, nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
func Values ¶
Values is a helper that converts an array command reply to a []interface{}. If err is not equal to nil, then Values returns nil, err. Otherwise, Values converts the reply as follows:
Reply type Result array reply, nil nil nil, ErrNil other nil, error
func WritePidById ¶
Types ¶
type Checkpoint ¶
type Checkpoint struct { /* * version: 0(or set not), MongoShake < 2.4, fcv == 0 * version: 1, MongoShake == 2.4, 0 < fcv <= 1 */ CurrentVersion int FeatureCompatibleVersion int }
for checkpoint
func (Checkpoint) IsCompatible ¶
func (c Checkpoint) IsCompatible(v int) bool
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 Configuration ¶
type Configuration struct { /* * version: 0(or set not), MongoShake < 2.4.0, fcv == 0 * version: 1, MongoShake == 2.4.0, 0 <= fcv <= 1 */ CurrentVersion int FeatureCompatibleVersion int }
for configuration
func (Configuration) IsCompatible ¶
func (c Configuration) IsCompatible(v int) bool