redis

package
v0.0.0-...-3430a5a Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasterRole = "master"
	SlaveRole  = "slave"
)
View Source
const (
	ClusterStateOk   string = "ok"
	ClusterStateFail string = "fail"
)

Variables

View Source
var (
	ErrNil     = redis.ErrNil
	Int        = redis.Int
	Ints       = redis.Ints
	IntMap     = redis.IntMap
	Int64      = redis.Int64
	Int64s     = redis.Int64s
	Int64Map   = redis.Int64Map
	Uint64     = redis.Uint64
	Uint64s    = redis.Uint64s
	Uint64Map  = redis.Uint64Map
	Float64    = redis.Float64
	Float64s   = redis.Float64s
	Float64Map = redis.Float64Map
	String     = redis.String
	Strings    = redis.Strings
	StringMap  = redis.StringMap
	Bytes      = redis.Bytes
	ByteSlices = redis.ByteSlices
	Bool       = redis.Bool
	Values     = redis.Values
	Positions  = redis.Positions
)

Functions

This section is empty.

Types

type Address

type Address string

func (Address) Host

func (a Address) Host() string

func (Address) Port

func (a Address) Port() int

func (Address) String

func (a Address) String() string

type AuthConfig

type AuthConfig struct {
	Username  string
	Password  string
	TLSConfig *tls.Config
}

type AuthInfo

type AuthInfo = AuthConfig

type ClusterNode

type ClusterNode struct {
	Id        string
	Addr      string
	RawFlag   string
	BusPort   string
	AuxFields ClusterNodeAuxFields
	Role      string
	MasterId  string
	PingSend  int64
	PongRecv  int64
	Epoch     int64
	LinkState string
	// contains filtered or unexported fields
}

func ParseNodeFromClusterNode

func ParseNodeFromClusterNode(line string) (*ClusterNode, error)

ParseNodeFromClusterNode format:

<id> <ip:port@cport> <flags> <master> <ping-sent> <pong-recv> <config-epoch> <link-state> <slot> <slot> ... <slot>

func (*ClusterNode) IsConnected

func (n *ClusterNode) IsConnected() bool

func (*ClusterNode) IsFailed

func (n *ClusterNode) IsFailed() bool

func (*ClusterNode) IsJoined

func (n *ClusterNode) IsJoined() bool

func (*ClusterNode) IsSelf

func (n *ClusterNode) IsSelf() bool

func (*ClusterNode) Raw

func (n *ClusterNode) Raw() string

func (*ClusterNode) Slots

func (n *ClusterNode) Slots() *slot.Slots

type ClusterNodeAuxFields

type ClusterNodeAuxFields struct {
	ShardID  string `json:"shard-id"`
	NodeName string `json:"nodename"`
	TCPPort  int64  `json:"tcp-port"`
	TLSPort  int64  `json:"tls-port"`
	// contains filtered or unexported fields
}

func (*ClusterNodeAuxFields) Raw

func (c *ClusterNodeAuxFields) Raw() string

type ClusterNodes

type ClusterNodes []*ClusterNode

func ParseNodes

func ParseNodes(data string) (nodes ClusterNodes, err error)

parseNodes

func (ClusterNodes) Get

func (ns ClusterNodes) Get(id string) *ClusterNode

func (ClusterNodes) Marshal

func (ns ClusterNodes) Marshal() ([]byte, error)

func (ClusterNodes) Masters

func (ns ClusterNodes) Masters() (ret []*ClusterNode)

func (ClusterNodes) Replicas

func (ns ClusterNodes) Replicas(id string) (ret []*ClusterNode)

func (ClusterNodes) Self

func (ns ClusterNodes) Self() *ClusterNode

type PipelineResult

type PipelineResult struct {
	Value any
	Error error
}

type RedisClient

type RedisClient interface {
	Do(ctx context.Context, cmd string, args ...any) (any, error)
	DoWithTimeout(ctx context.Context, timeout time.Duration, cmd string, args ...interface{}) (interface{}, error)
	Tx(ctx context.Context, cmds []string, args [][]any) (interface{}, error)
	Pipeline(ctx context.Context, args [][]any) ([]PipelineResult, error)
	Close() error
	Clone(ctx context.Context, addr string) RedisClient

	Ping(ctx context.Context) error
	Info(ctx context.Context, sections ...any) (*RedisInfo, error)
	ClusterInfo(ctx context.Context) (*RedisClusterInfo, error)
	ConfigGet(ctx context.Context, cate string) (map[string]string, error)
	ConfigSet(ctx context.Context, params map[string]string) error
	Nodes(ctx context.Context) (ClusterNodes, error)
}

RedisClient

func NewRedisClient

func NewRedisClient(addr string, authInfo AuthConfig) RedisClient

NewRedisClient

type RedisClusterInfo

type RedisClusterInfo struct {
	ClusterState         string `json:"cluster_state"`
	ClusterSlotsAssigned int    `json:"cluster_slots_assigned"`
	ClusterSlotsOk       int    `json:"cluster_slots_ok"`
	ClusterSlotsPfail    int    `json:"cluster_slots_pfail"`
	ClusterSlotsFail     int    `json:"cluster_slots_fail"`
	ClusterKnownNodes    int    `json:"cluster_known_nodes"`
	ClusterSize          int    `json:"cluster_size"`
	ClusterCurrentEpoch  int    `json:"cluster_current_epoch"`
	ClusterMyEpoch       int    `json:"cluster_my_epoch"`
}

type RedisInfo

type RedisInfo struct {
	RedisVersion          string `json:"redis_version"`
	RedisMode             string `json:"redis_mode"`
	RunId                 string `json:"run_id"`
	UptimeInSeconds       int64  `json:"uptime_in_seconds"`
	AOFEnabled            string `json:"aof_enabled"`
	Role                  string `json:"role"`
	ConnectedReplicas     int64  `json:"connected_slaves"`
	MasterHost            string `json:"master_host"`
	MasterPort            string `json:"master_port"`
	ClusterEnabled        string `json:"cluster_enabled"`
	MasterLinkStatus      string `json:"master_link_status"`
	MasterReplId          string `json:"master_replid"`
	MasterReplOffset      int64  `json:"master_repl_offset"`
	UsedMemory            int64  `json:"used_memory"`
	UsedMemoryDataset     int64  `json:"used_memory_dataset"`
	SentinelMasters       int64  `json:"sentinel_masters"`
	SentinelTiLt          int64  `json:"sentinel_tilt"`
	SentinelRunningScript int64  `json:"sentinel_running_scripts"`
	SentinelMaster0       struct {
		Name            string                `json:"name"`
		Status          string                `json:"status"`
		Address         Address               `json:"address"`
		Replicas        int                   `json:"slaves"`
		Sentinels       int                   `json:"sentinels"`
		MonitorReplicas []SentinelMonitorNode `json:"monitor_replicas"`
	} `json:"master0"`
}

RedisInfo

type SentinelMonitorNode

type SentinelMonitorNode struct {
	Name                  string `json:"name"`
	IP                    string `json:"ip"`
	Port                  string `json:"port"`
	RunId                 string `json:"run_id"`
	Flags                 string `json:"flags"`
	LinkPendingCommands   int32  `json:"link_pending_commands"`
	LinkRefcount          int32  `json:"link_refcount"`
	FailoverState         string `json:"failover_state"`
	LastPingSent          int64  `json:"last_ping_sent"`
	LastOkPingReply       int64  `json:"last_ok_ping_reply"`
	LastPingReply         int64  `json:"last_ping_reply"`
	SDownTime             int64  `json:"s_down_time"`
	ODownTime             int64  `json:"o_down_time"`
	DownAfterMilliseconds int64  `json:"down_after_milliseconds"`
	InfoRefresh           int64  `json:"info_refresh"`
	RoleReported          string `json:"role_reported"`
	RoleReportedTime      int64  `json:"role_reported_time"`
	ConfigEpoch           int64  `json:"config_epoch"`
	NumSlaves             int32  `json:"num_slaves"`
	NumOtherSentinels     int32  `json:"num_other_sentinels"`
	Quorum                int32  `json:"quorum"`
	FailoverTimeout       int64  `json:"failover_timeout"`
	ParallelSyncs         int32  `json:"parallel_syncs"`

	// replica fields
	MasterLinkDownTime int64  `json:"master_link_down_time"`
	MasterLinkStatus   string `json:"master_link_status"`
	MasterHost         string `json:"master_host"`
	MasterPort         string `json:"master_port"`
	SlavePriority      int32  `json:"slave_priority"`
	SlaveReplOffset    int64  `json:"slave_repl_offset"`

	// sentinel node specific fields
	LastHelloMessage string `json:"last_hello_message"`
	VotedLeader      string `json:"voted_leader"`
	VotedLeaderEpoch int64  `json:"voted_leader_epoch"`
}

func ParseSentinelMonitorNode

func ParseSentinelMonitorNode(val interface{}) *SentinelMonitorNode

func (*SentinelMonitorNode) Address

func (s *SentinelMonitorNode) Address() string

func (*SentinelMonitorNode) IsFailovering

func (s *SentinelMonitorNode) IsFailovering() bool

func (*SentinelMonitorNode) IsMaster

func (s *SentinelMonitorNode) IsMaster() bool

Jump to

Keyboard shortcuts

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