myredis

package
v0.0.0-...-ad947ae Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	G_Redis_BigKey_Format_Data      string         = "%-2d, %-10d, %-10d, %-6s, %-19s, %-10d, %-20s, %-20s\n"
	G_Redis_BigKey_Format_Header    string         = "%-2s, %-10s, %-10s, %-6s, %-19s, %-10s, %-20s, %-20s\n"
	G_Redis_BigKey_Headers          []string       = []string{"db", "sizeInByte", "elementCnt", "type", "expire", "bigSize", "key", "big"}
	G_regexp_info_keyspace_db       *regexp.Regexp = regexp.MustCompile(`db\d+`)
	G_regexp_info_replication_slave *regexp.Regexp = regexp.MustCompile(`slave\d+`)
)

Functions

func GetAllMastersAddr

func GetAllMastersAddr(sarr map[string]*ClusterNodeInfo) []string

func GetAllSlavesAddr

func GetAllSlavesAddr(sarr map[string]*ClusterNodeInfo) []string

func GetClusterNodesInfo

func GetClusterNodesInfo(client *redis.ClusterClient) (map[string]*ClusterNodeInfo, error)

name addr flags role ping_sent ping_recv config_epoch link_status slots 37328e760f7c5ca1f0430cd59bb6fcae7099e3aa 10.199.203.210:6681 myself,master - 0 0 7 connected 2731-5460 06934f9263df8e6292d2accecef2a6cabc5193a8 10.199.203.210:6683 slave 9fd094136d8ae049dcf8f8e4ff833015ce9186a9 0 1512612681090 13 connected 2725ea3036cd2948d45d82fb8b192b91805b1fbb 10.201.42.179:8209 myself,master - 0 0 1 connected 6823-8191 [6823->-b73527c7435d8b104709dd644c39b0e06ffce96b] b73527c7435d8b104709dd644c39b0e06ffce96b 10.201.41.189:8219 myself,master - 0 0 30 connected [6823-<-2725ea3036cd2948d45d82fb8b192b91805b1fbb]

key = host:port

func GetLatestSlaveOfMasters

func GetLatestSlaveOfMasters(masters []string) (map[string]string, []string, []string, error)

func GetRedisAddr

func GetRedisAddr(host string, port int) string

func GetRedisBigkeyHeader

func GetRedisBigkeyHeader() string

func ParseDBkeyspce

func ParseDBkeyspce(line string) (uint64, uint64, float64, error)

func ParseInfoClient

func ParseInfoClient(result map[string]string, info *RedisInfoAll)

func ParseInfoKeyspace

func ParseInfoKeyspace(result map[string]string, info *RedisInfoAll)

func ParseInfoMemory

func ParseInfoMemory(result map[string]string, info *RedisInfoAll)

func ParseInfoPersistent

func ParseInfoPersistent(result map[string]string, info *RedisInfoAll)

func ParseInfoReplication

func ParseInfoReplication(result map[string]string, info *RedisInfoAll)

func ParseInfoSever

func ParseInfoSever(result map[string]string, info *RedisInfoAll)

func ParseInfoStats

func ParseInfoStats(result map[string]string, info *RedisInfoAll)

func ScanRedisKeys

func ScanRedisKeys(client *redis.Client, scanCnt int64, matchRe *regexp.Regexp, sleepCnt int, sleepTime int, keysChan chan string) error

Types

type ClusterAndRedisClient

type ClusterAndRedisClient struct {
	Redis     *redis.Client
	Cluster   *redis.ClusterClient
	IsCluster bool
}

func GetClusterOrRedisClient

func GetClusterOrRedisClient(cfg ConfCommon, addrs []string, readOnly bool, db int, isCluster bool) (ClusterAndRedisClient, error)

func (ClusterAndRedisClient) CheckIfCluster

func (client ClusterAndRedisClient) CheckIfCluster() (bool, error)

func (ClusterAndRedisClient) DeleteKeyList

func (client ClusterAndRedisClient) DeleteKeyList(key string, length int64, eachCnt int64, elementBatch int64,
	elementInterval time.Duration, ifSleep bool) error

func (ClusterAndRedisClient) DeleteKeyString

func (client ClusterAndRedisClient) DeleteKeyString(key string) error

func (ClusterAndRedisClient) DeleteKeysByDirectlyDelIt

func (client ClusterAndRedisClient) DeleteKeysByDirectlyDelIt(keyes []string) error

func (ClusterAndRedisClient) DeleteKeysByExpireIt

func (client ClusterAndRedisClient) DeleteKeysByExpireIt(keyes []string, expTime time.Duration) error

delete key by setting expire time of key to little seconds.

func (ClusterAndRedisClient) GetClusterInfoAll

func (client ClusterAndRedisClient) GetClusterInfoAll() (ClusterInfoAll, error)

func (ClusterAndRedisClient) GetClusterInfoString

func (client ClusterAndRedisClient) GetClusterInfoString() (map[string]string, error)

func (ClusterAndRedisClient) GetHashValue

func (client ClusterAndRedisClient) GetHashValue(key string, eachCnt int64, elementBatch int,
	elementInterval time.Duration, ifSleep bool, ifBytes bool) (map[string]interface{},
	int, string, int, int, error)

func (ClusterAndRedisClient) GetKeyTTL

func (client ClusterAndRedisClient) GetKeyTTL(key string, timeFmt string) (string, error)

func (ClusterAndRedisClient) GetKeyType

func (client ClusterAndRedisClient) GetKeyType(key string) (string, error)

func (ClusterAndRedisClient) GetKeyValue

func (client ClusterAndRedisClient) GetKeyValue(key string, eachCnt int64, elementBatch int, elementInterval time.Duration, ifSleep bool,
	ifCountMem bool, ifNeedValue bool) (RedisKey, error)

get one key info and value

func (ClusterAndRedisClient) GetLatestSlave

func (client ClusterAndRedisClient) GetLatestSlave(slaves []SlaveInfo) (SlaveInfo, error)

func (ClusterAndRedisClient) GetListLen

func (client ClusterAndRedisClient) GetListLen(key string) (int64, error)

func (ClusterAndRedisClient) GetListValue

func (client ClusterAndRedisClient) GetListValue(key string, length int64, eachCnt int64, elementBatch int,
	elementInterval time.Duration, ifSleep bool, ifBytes bool) ([]string, int, string, int, error)

param: key name, key length, count of elements to get each time, sleep after this process elementBatch element, esleep time for elementInterval in microsecond, if sleep, if calculate memory used in bytes return: value, bytes of the key, biggest element, bytes of the biggest element, error

func (ClusterAndRedisClient) GetRedisConfVars

func (client ClusterAndRedisClient) GetRedisConfVars(ifErrBreak bool) (RedisConfVar, error)

func (ClusterAndRedisClient) GetRedisInfo

func (client ClusterAndRedisClient) GetRedisInfo(section string) (map[string]string, error)

func (ClusterAndRedisClient) GetRedisInfoAll

func (client ClusterAndRedisClient) GetRedisInfoAll(selfIps []string, port int, ifGetSlaveLag bool) (RedisInfoAll, error)

func (ClusterAndRedisClient) GetRedisInfoRole

func (client ClusterAndRedisClient) GetRedisInfoRole() (RedisRoleInfo, error)

func (ClusterAndRedisClient) GetRedisOneVarInt64

func (client ClusterAndRedisClient) GetRedisOneVarInt64(name string) (int64, error)

func (ClusterAndRedisClient) GetRedisOneVarString

func (client ClusterAndRedisClient) GetRedisOneVarString(name string) (string, error)

func (ClusterAndRedisClient) GetRedisOneVarUint64

func (client ClusterAndRedisClient) GetRedisOneVarUint64(name string) (uint64, error)

func (ClusterAndRedisClient) GetSetValue

func (client ClusterAndRedisClient) GetSetValue(key string, eachCnt int64, elementBatch int,
	elementInterval time.Duration, ifSleep bool, ifBytes bool) ([]string, int, string, int, int, error)

param: key name, count of elements to get each time, sleep after processing elementBatch elements,

sleep for elementInterval in microsecond, if calculate memory used in bytes

return: value, bytes of the key, biggest element, bytes of the biggest element, error

func (ClusterAndRedisClient) GetSlaveReplInfo

func (client ClusterAndRedisClient) GetSlaveReplInfo(infoStr string) (SlaveInfo, error)

func (ClusterAndRedisClient) GetSlavesReplicationStatus

func (client ClusterAndRedisClient) GetSlavesReplicationStatus(slaveIps map[string]int) (int64, int64, error)

func (ClusterAndRedisClient) GetStringValue

func (client ClusterAndRedisClient) GetStringValue(key string, ifBytes bool) (string, int, error)

func (ClusterAndRedisClient) GetZsetValue

func (client ClusterAndRedisClient) GetZsetValue(key string, eachCnt int64, elementBatch int,
	elementInterval time.Duration, ifSleep bool, ifBytes bool) (map[string]float64, int, string, int, int, error)

func (ClusterAndRedisClient) RedisPing

func (client ClusterAndRedisClient) RedisPing() bool

type ClusterAndRedisConf

type ClusterAndRedisConf struct {
	Redis     *redis.Options
	Cluster   *redis.ClusterOptions
	IsCluster bool
}

type ClusterInfoAll

type ClusterInfoAll struct {
	Cluster_state          int64 // OK: 1, 0: not ok
	Cluster_slots_assigned uint64
	Cluster_slots_ok       uint64
	Cluster_slots_pfail    uint64
	Cluster_slots_fail     uint64
}

type ClusterNodeInfo

type ClusterNodeInfo struct {
	NodeId      string
	Addr        string
	Flags       []string
	Role        string // master|slave
	PingSent    int
	PingRecv    int
	ConfEpoch   int
	LinkStatus  string //connected
	Slots       []int
	RehashSlots []SlotRehash
	MasterId    string
	MasterAddr  string
}

type ConfCluster

type ConfCluster struct {
	ConfCommon
	Addrs []string // host:port

	ReadOnly bool // if read slave

	MaxRedirects int
}

func (ConfCluster) CreateNewClientCluster

func (this ConfCluster) CreateNewClientCluster() (*redis.ClusterClient, error)

type ConfCommon

type ConfCommon struct {
	Password   string
	MaxRetries int

	DialTimeout  int
	ReadTimeout  int
	WriteTimeout int

	PoolSize           int
	PoolTimeout        int
	IdleTimeout        int
	IdleCheckFrequency int
}

type ConfRedis

type ConfRedis struct {
	ConfCommon
	//Network  string // tcp|unix
	Addr     string //host:port | socket
	Database int    // db number
}

func (ConfRedis) CreateNewClientRedis

func (this ConfRedis) CreateNewClientRedis() (*redis.Client, error)

type RedisAddr

type RedisAddr struct {
	Host string
	Port int
}

type RedisConfVar

type RedisConfVar struct {
	Maxmemory                     uint64
	Cluster_node_timeout          uint64
	Cluster_require_full_coverage int64 // yes: 1, no: 0
	Slave_serve_stale_data        int64 // yes:1, no:0
	Slave_read_only               int64 // yes:1, no:0
	Stop_writes_on_bgsave_error   int64 // yes:1, no:0
}

type RedisInfoAll

type RedisInfoAll struct {
	Redis_version              string
	IsCluster                  int64 // cluster:1, redis:0
	Process_id                 uint64
	Total_connections_received uint64
	Connected_clients          uint64
	Rejected_connections       uint64
	Blocked_clients            uint64
	Client_longest_output_list uint64
	Client_biggest_input_buf   uint64
	Total_commands_processed   uint64
	Instantaneous_ops_per_sec  float64
	Keyspace_hits              uint64
	Keyspace_misses            uint64
	Expired_keys               uint64
	Evicted_keys               uint64
	Keys_alldb                 uint64 // number of keys of all db
	Keys_expires               uint64 // number of keys with expiration of all db
	Total_net_input_bytes      uint64
	Total_net_output_bytes     uint64
	Instantaneous_input_kbps   float64
	Instantaneous_output_kbps  float64
	Used_memory                uint64
	Used_memory_rss            uint64
	Used_memory_peak           uint64
	Used_memory_lua            uint64
	Mem_fragmentation_ratio    float64
	LoadingRdb                 int64
	Rdb_bgsave_in_progress     int64
	Rdb_last_bgsave_status     int64 // ok: 0, error: 1
	Aof_rewrite_in_progress    int64
	Aof_last_bgrewrite_status  int64 // ok: 0, error: 1
	Aof_last_write_status      int64 // ok: 0, error: 1
	Pubsub_channels            uint64
	Pubsub_patterns            uint64
	Role                       string
	Connected_slaves           uint64
	Master_host                string
	Master_port                uint64
	Master_link_status         int64 // up: 1, else: 0
	SlaveLag                   int64
	Master_sync_in_progress    int64
}

type RedisKey

type RedisKey struct {
	Database        uint
	Bytes           int // bytes of key and value
	ElementCnt      int // for list|set|hash|zset, the count of the elements
	Type            string
	Expire          string
	MaxElementBytes int    // bytes of max element of key
	Key             string // key
	MaxElement      string // max element of key
	Value           interface{}
}

func (RedisKey) DumpJsonStr

func (this RedisKey) DumpJsonStr(ifPretty bool, indent string) (string, error)

func (RedisKey) GetRedisKeyPrintLine

func (this RedisKey) GetRedisKeyPrintLine(ifBigkey bool, ifPretty bool, indent string) (string, error)

func (RedisKey) ToStringWithoutValue

func (this RedisKey) ToStringWithoutValue() string

type RedisRoleInfo

type RedisRoleInfo struct {
	Role        string // master or slave
	MasterAddr  RedisAddr
	Replicating bool        // for slave, master_link_status:up
	Slaves      []SlaveInfo // for master
}

type SlaveInfo

type SlaveInfo struct {
	Addr        RedisAddr
	Replicating bool // state=online
	Lag         int
	Offset      int
}

type SlotRehash

type SlotRehash struct {
	Slot      int
	SrcId     string
	SrcAddr   string
	DestId    string
	DestAddr  string
	IsMigrate bool // true: migrate, false: importing

}

func SlotsStrToSeperateInts

func SlotsStrToSeperateInts(slts []string) ([]int, []SlotRehash)

Jump to

Keyboard shortcuts

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