rediscli

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERR_STRINGS = map[string]string{
	"idnotdef":        "No such node ID",
	"nodenotmaster":   "The specified node is not a master",
	"unknown":         "Unknown node",
	"failoverreplica": "ERR You should send CLUSTER FAILOVER to a replica",
}
View Source
var SHARED_ERR_STRINGS = map[string]string{
	"wrongtype":     "WRONGTYPE Operation against a key holding the wrong kind of value",
	"nokeyerr":      "ERR no such key",
	"syntaxerr":     "ERR syntax error",
	"srcdsterr":     "ERR source and destination objects are the same",
	"indexrangeerr": "ERR index out of range",
	"noscript":      "NOSCRIPT No matching script. Please use EVAL",
	"loading":       "LOADING Redis is loading the dataset in memory",
	"busy":          "BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE",
	"masterdown":    "MASTERDOWN Link with MASTER is down and replica-serve-stale-data is set to 'no'",
	"misconf":       "MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk",
	"readonly":      "READONLY You can't write against a read only replica",
	"noauth":        "NOAUTH Authentication required",
	"oom":           "OOM command not allowed when used memory > 'maxmemory'",
	"execabort":     "EXECABORT Transaction discarded because of previous errors",
	"noreplicas":    "NOREPLICAS Not enough good replicas to write",
	"busykey":       "BUSYKEY Target key name already exists",
}

https://github.com/redis/redis/blob/899c85ae67631f4f9f866a254ac5e149b86e5529/src/server.c#L2493

Functions

func IsError

func IsError(message string) bool

Checks if a given string matches any supported redis-cli error types

func IsFailoverNotOnReplica

func IsFailoverNotOnReplica(err error) bool

func IsGenericError

func IsGenericError(err error) bool

Checks if an error is prefixed by the generic ERR string

func IsLoading

func IsLoading(err error) bool

func IsNodeIsNotMaster

func IsNodeIsNotMaster(err error) bool

func Pprint

func Pprint(str interface{}) string

func SortACLFields

func SortACLFields(acl *RedisACL)

Types

type ByName

type ByName []RedisACLUser

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type RedisACL

type RedisACL struct {
	Users []RedisACLUser
}

func NewRedisACL

func NewRedisACL(rawData string) (*RedisACL, error)

func (*RedisACL) String

func (r *RedisACL) String() string

type RedisACLChannels

type RedisACLChannels struct {
	Patterns      []string
	AllChannels   bool
	ResetChannels bool
}

func (*RedisACLChannels) String

func (t *RedisACLChannels) String() string

type RedisACLCommands

type RedisACLCommands struct {
	Commands    []string
	RmCommands  []string
	AllCommands bool
	NoCommands  bool
}

Important: the struct will not preserve the order of remove and add operations, please group all removes and adds together

func (*RedisACLCommands) String

func (t *RedisACLCommands) String() string

type RedisACLKeys

type RedisACLKeys struct {
	Patterns  []string
	AllKeys   bool
	ResetKeys bool
}

func (*RedisACLKeys) String

func (t *RedisACLKeys) String() string

type RedisACLPasswords

type RedisACLPasswords struct {
	Passwords   []string
	RmPasswords []string
	Hashes      []string
	RmHashes    []string
	NoPass      bool
	ResetPass   bool
}

func (*RedisACLPasswords) String

func (t *RedisACLPasswords) String() string

type RedisACLUser

type RedisACLUser struct {
	Name      string
	On        bool
	Reset     bool
	Commands  RedisACLCommands
	Keys      RedisACLKeys
	Channels  RedisACLChannels
	Passwords RedisACLPasswords
}

type RedisAuth

type RedisAuth struct {
	User string
}

type RedisCLI

type RedisCLI struct {
	Log  logr.Logger
	Auth *RedisAuth
}

func NewRedisCLI

func NewRedisCLI(log *logr.Logger) *RedisCLI

func (*RedisCLI) ACLList

func (r *RedisCLI) ACLList(nodeIP string) (*RedisACL, error)

https://redis.io/commands/acl-list

func (*RedisCLI) ACLLoad

func (r *RedisCLI) ACLLoad(nodeIP string) (string, error)

https://redis.io/commands/acl-load

func (*RedisCLI) AddFollower

func (r *RedisCLI) AddFollower(newNodeIP string, nodeIP string, leaderID string) (string, error)

AddFollower uses the '--cluster add-node' option on redis-cli to add a node to the cluster newNodeIP: IP of the follower that will join the cluster nodeIP: IP of a node in the cluster leaderID: Redis ID of the leader that the new follower will replicate

func (*RedisCLI) ClusterCheck

func (r *RedisCLI) ClusterCheck(nodeIP string) (string, error)

func (*RedisCLI) ClusterCreate

func (r *RedisCLI) ClusterCreate(leaderIPs []string) (string, error)

ClusterCreate uses the '--cluster create' option on redis-cli to create a cluster using a list of nodes

func (*RedisCLI) ClusterFailover

func (r *RedisCLI) ClusterFailover(nodeIP string, opt ...string) (string, error)

https://redis.io/commands/cluster-failover

func (*RedisCLI) ClusterForget

func (r *RedisCLI) ClusterForget(nodeIP string, forgetNodeID string) (string, error)

ForgetNode command is used in order to remove a node, specified via its node ID, from the set of known nodes of the Redis Cluster node receiving the command. In other words the specified node is removed from the nodes table of the node receiving the command. https://redis.io/commands/cluster-forget

func (*RedisCLI) ClusterInfo

func (r *RedisCLI) ClusterInfo(nodeIP string) (*RedisClusterInfo, error)

https://redis.io/commands/cluster-info

func (*RedisCLI) ClusterMeet

func (r *RedisCLI) ClusterMeet(nodeIP string, newNodeIP string, newNodePort string, newNodeBusPort ...string) (string, error)

https://redis.io/commands/cluster-meet

func (*RedisCLI) ClusterNodes

func (r *RedisCLI) ClusterNodes(nodeIP string) (*RedisClusterNodes, error)

https://redis.io/commands/cluster-nodes

func (*RedisCLI) ClusterReplicas

func (r *RedisCLI) ClusterReplicas(nodeIP string, leaderNodeID string) (*RedisClusterNodes, error)

ClusterReplicas command provides a list of replica nodes replicating from a specified leader node https://redis.io/commands/cluster-replicas

func (*RedisCLI) ClusterReplicate

func (r *RedisCLI) ClusterReplicate(nodeIP string, leaderID string) (string, error)

https://redis.io/commands/cluster-replicate

func (*RedisCLI) ClusterReset

func (r *RedisCLI) ClusterReset(nodeIP string, opt ...string) (string, error)

https://redis.io/commands/cluster-reset

func (*RedisCLI) DelNode

func (r *RedisCLI) DelNode(nodeIP string, nodeID string) (string, error)

DelNode uses the '--cluster del-node' option of redis-cli to remove a node from the cluster nodeIP: any node of the cluster nodeID: node that needs to be removed

func (*RedisCLI) Flushall

func (r *RedisCLI) Flushall(nodeIP string, opt ...string) (string, error)

https://redis.io/commands/flushall

func (*RedisCLI) Info

func (r *RedisCLI) Info(nodeIP string) (*RedisInfo, error)

https://redis.io/commands/info

func (*RedisCLI) MyClusterID

func (r *RedisCLI) MyClusterID(nodeIP string) (string, error)

https://redis.io/commands/cluster-myid

func (*RedisCLI) Ping

func (r *RedisCLI) Ping(nodeIP string, message ...string) (string, error)

https://redis.io/commands/ping

type RedisClusterInfo

type RedisClusterInfo map[string]string

https://redis.io/commands/cluster-info

func NewRedisClusterInfo

func NewRedisClusterInfo(rawData string) *RedisClusterInfo

func (*RedisClusterInfo) IsClusterFail

func (r *RedisClusterInfo) IsClusterFail() bool

type RedisClusterNode

type RedisClusterNode struct {
	ID          string
	Addr        string
	Flags       string
	Leader      string
	PingSend    string
	PingRecv    string
	ConfigEpoch string
	LinkState   string
}

func (*RedisClusterNode) IsFailing

func (r *RedisClusterNode) IsFailing() bool

IsFailing method return true when the current redis node is in failing state and needs to be forgotten by the cluster

type RedisClusterNodes

type RedisClusterNodes []RedisClusterNode

RedisClusterNodes command: https://redis.io/commands/cluster-nodes

func NewRedisClusterNodes

func NewRedisClusterNodes(rawData string) *RedisClusterNodes

NewRedisClusterNodes is a constructor for RedisClusterNodes

func (*RedisClusterNodes) GetIDForIP

func (r *RedisClusterNodes) GetIDForIP(ip string) string

Returns the Redis node ID for a specified IP or empty string if IP not found Supports the IP and IP:port format

func (*RedisClusterNodes) GetIPForID

func (r *RedisClusterNodes) GetIPForID(id string) (string, string)

Returns the IP and port for a given Redis ID or empty strings if ID not found

type RedisInfo

type RedisInfo struct {
	Server      map[string]string
	Clients     map[string]string
	Memory      map[string]string
	Persistence map[string]string
	Stats       map[string]string
	Replication map[string]string
	CPU         map[string]string
	Cluster     map[string]string
	Modules     map[string]string
	Keyspace    map[string]string
}

https://redis.io/commands/info

func NewRedisInfo

func NewRedisInfo(rawInfo string) *RedisInfo

func (*RedisInfo) GetLoadETA

func (r *RedisInfo) GetLoadETA() string

GetLoadETA indicating if the load of a dump file is on-going If a load operation is on-going, it returns the ETA to finish.

func (*RedisInfo) GetSyncStatus

func (r *RedisInfo) GetSyncStatus() string

Returns the estimated completion percentage or the empty string if SYNC is not in progress

Jump to

Keyboard shortcuts

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