redis

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// PackageName is the package name.
	PackageName = "go-redis"
	// LocalHost is the local host name.
	LocalHost = "localhost"
	// DefaultPort is the default port number.
	DefaultPort = 6379
	// DefaultTLSPort is the default TLS port number.
	DefaultTLSPort = 0
	// DefaultScanCount is the default scan count.
	DefaultScanCount = 10
	// DefaultScanPattern is the default scan pattern.
	DefaultScanPattern = "*"
	// DefaultScanType is the default scan type.
	DefaultScanType = KeyScan
)
View Source
const (
	ConfigSep = " "
)
View Source
const (
	OK = "OK"
)
View Source
const (
	Version = "v1.5.3"
)

Variables

View Source
var (
	ErrNotSupported = errors.New("not supported")
	ErrQuit         = errors.New("QUIT")
	ErrSystem       = errors.New("internal system error")
	ErrNotAuthrized = errors.New("not authrized")
	ErrInvalid      = errors.New("invalid")
)

Functions

func NewErrNotSupported added in v1.4.0

func NewErrNotSupported(target string) error

NewErrNotSupported returns a new ErrNotSupported.

func NewTLSConfigFrom added in v1.5.0

func NewTLSConfigFrom(config *ServerConfig) (*tls.Config, error)

NewTLSConfigFrom returns a new TLS configuration from the specified server configuration.

Types

type Arguments added in v1.0.0

type Arguments = *proto.Array

type AuthCommandHandler added in v1.4.0

type AuthCommandHandler interface {
	Auth(conn *Conn, username string, password string) (*Message, error)
}

AuthCommandHandler represents a hander interface for authentication commands.

type Config added in v1.2.0

type Config struct {
	// contains filtered or unexported fields
}

Config represents a server configuration.

func (*Config) AppendConfig added in v1.2.0

func (cfg *Config) AppendConfig(key string, params string)

AppendConfig appends a specified parameter.

func (*Config) ConfigInteger added in v1.5.0

func (cfg *Config) ConfigInteger(key string) (int, bool)

ConfigInteger returns the specified parameter as an integer.

func (*Config) ConfigString added in v1.5.0

func (cfg *Config) ConfigString(key string) (string, bool)

ConfigString return the specified parameter.

func (*Config) RemoveConfig added in v1.4.0

func (cfg *Config) RemoveConfig(key string)

RemoveConfig removes the specified parameter.

func (*Config) SetConfig added in v1.2.0

func (cfg *Config) SetConfig(key string, params string)

SetConfig sets a specified parameter.

type Conn added in v1.3.0

type Conn struct {
	net.Conn

	sync.Map

	tracer.Context
	// contains filtered or unexported fields
}

Conn represents a database connection.

func (*Conn) Close added in v1.5.3

func (conn *Conn) Close() error

Close closes the connection.

func (*Conn) Database added in v1.3.0

func (conn *Conn) Database() DatabaseID

Database returns the current selected database number in the connection.

func (*Conn) IsAuthrized added in v1.4.0

func (conn *Conn) IsAuthrized() bool

IsAuthrized returns true if the connection is authrized.

func (*Conn) IsTLSConnection added in v1.5.2

func (conn *Conn) IsTLSConnection() bool

IsTLSConnection return true if the connection is enabled TLS.

func (*Conn) Password added in v1.5.2

func (conn *Conn) Password() (string, bool)

Password returns the password and true if the connection has the password.

func (*Conn) SetAuthrized added in v1.4.0

func (conn *Conn) SetAuthrized(authrized bool)

SetAuthrized sets the authrized flag to the connection.

func (*Conn) SetDatabase added in v1.3.0

func (conn *Conn) SetDatabase(id DatabaseID)

SetDatabase sets the selected database number to the connection.

func (*Conn) SetPassword added in v1.5.2

func (conn *Conn) SetPassword(password string)

SetPassword sets the password to the connection.

func (*Conn) SetSpanContext added in v1.3.5

func (conn *Conn) SetSpanContext(span tracer.Context)

SetAuthrizedxt to the connection.

func (*Conn) SetUserName added in v1.5.2

func (conn *Conn) SetUserName(username string)

SetUserName sets the user name to the connection.

func (*Conn) SpanContext added in v1.3.5

func (conn *Conn) SpanContext() tracer.Context

SpanContext returns the span context of the connection.

func (*Conn) TLSConnectionState added in v1.5.2

func (conn *Conn) TLSConnectionState() (*tls.ConnectionState, bool)

TLSConnectionState returns the TLS connection state.

func (*Conn) Timestamp added in v1.3.0

func (conn *Conn) Timestamp() time.Time

Timestamp returns the creation time of the connection.

func (*Conn) UUID added in v1.5.3

func (conn *Conn) UUID() uuid.UUID

UUID returns the UUID of the connection.

func (*Conn) UserName added in v1.5.2

func (conn *Conn) UserName() (string, bool)

UserName returns the user name and true if the connection has the user name.

type ConnManager added in v1.5.3

type ConnManager struct {
	// contains filtered or unexported fields
}

ConnManager represents a connection map.

func NewConnManager added in v1.5.3

func NewConnManager() *ConnManager

NewConnManager returns a connection map.

func (*ConnManager) AddConn added in v1.5.3

func (mgr *ConnManager) AddConn(c *Conn)

AddConn adds the specified connection.

func (*ConnManager) Close added in v1.5.3

func (mgr *ConnManager) Close() error

Close closes the connection manager.

func (*ConnManager) ConnByUUID added in v1.5.3

func (mgr *ConnManager) ConnByUUID(uuid uuid.UUID) (*Conn, bool)

ConnByUUID returns the connection with the specified UUID.

func (*ConnManager) Conns added in v1.5.3

func (mgr *ConnManager) Conns() []*Conn

Conns returns the included connections.

func (*ConnManager) RemoveConn added in v1.5.3

func (mgr *ConnManager) RemoveConn(conn *Conn) error

RemoveConn deletes the specified connection from the map.

func (*ConnManager) Start added in v1.5.3

func (mgr *ConnManager) Start() error

Start starts the connection manager.

func (*ConnManager) Stop added in v1.5.3

func (mgr *ConnManager) Stop() error

Stop closes all connections.

type ConnectionManagementCommandHandler added in v1.2.0

type ConnectionManagementCommandHandler interface {
	Ping(conn *Conn, arg string) (*Message, error)
	Echo(conn *Conn, arg string) (*Message, error)
	Select(conn *Conn, index int) (*Message, error)
	Quit(conn *Conn) (*Message, error)
}

ConnectionManagementCommandHandler represents a hander interface for connection management commands.

type DatabaseID added in v1.4.2

type DatabaseID = int

DatabaseID is a database ID.

type Executor added in v1.0.0

type Executor func(*Conn, string, Arguments) (*Message, error)

type Executors added in v1.0.0

type Executors map[string]Executor

type ExpireOption added in v1.0.0

type ExpireOption struct {
	Time time.Time
	NX   bool
	XX   bool
	GT   bool
	LT   bool
}

type GenericCommandHandler added in v1.0.0

type GenericCommandHandler interface {
	Del(conn *Conn, keys []string) (*Message, error)
	Exists(conn *Conn, keys []string) (*Message, error)
	Expire(conn *Conn, key string, opt ExpireOption) (*Message, error)
	Keys(conn *Conn, pattern string) (*Message, error)
	Rename(conn *Conn, key string, newkey string, opt RenameOption) (*Message, error)
	Type(conn *Conn, key string) (*Message, error)
	TTL(conn *Conn, key string) (*Message, error)
	Scan(conn *Conn, cursor int, opt ScanOption) (*Message, error)
}

GenericCommandHandler represents a hander interface for genelic commands.

type HSetOption added in v1.0.0

type HSetOption struct {
	NX bool
}

type HashCommandHandler added in v1.0.0

type HashCommandHandler interface {
	// HDel represents a handler interface for HDEL command.
	HDel(conn *Conn, key string, fields []string) (*Message, error)
	// HSet represents a handler interface for HSET and HSETNX commands.
	HSet(conn *Conn, key string, field string, val string, opt HSetOption) (*Message, error)
	// HGet represents a handler interface for HGET command.
	HGet(conn *Conn, key string, field string) (*Message, error)
	// HGetAll represents a handler interface for HGETALL command.
	HGetAll(conn *Conn, key string) (*Message, error)
}

HashCommandHandler represents a core command hander interface for hash commands. HMSET and HMGET commands are implemented by the HashCommandHandler.

type ListCommandHandler added in v1.1.0

type ListCommandHandler interface {
	LPush(conn *Conn, key string, elements []string, opt PushOption) (*Message, error)
	RPush(conn *Conn, key string, elements []string, opt PushOption) (*Message, error)
	LPop(conn *Conn, key string, count int) (*Message, error)
	RPop(conn *Conn, key string, count int) (*Message, error)
	LRange(conn *Conn, key string, start int, stop int) (*Message, error)
	LIndex(conn *Conn, key string, index int) (*Message, error)
	LLen(conn *Conn, key string) (*Message, error)
}

ListCommandHandler represents a core command hander interface for list commands.

type Message

type Message = proto.Message

Message represents a message of Redis serialization protocol.

func NewArrayMessage added in v1.0.0

func NewArrayMessage() *Message

NewArrayMessage creates an empty array message.

func NewArrayMessageWithArray added in v1.1.0

func NewArrayMessageWithArray(val *proto.Array) *Message

NewArrayMessageWithArray creates an array message with the specified array.

func NewBulkMessage

func NewBulkMessage(msg string) *Message

NewBulkMessage creates a bulk string message.

func NewErrorMessage

func NewErrorMessage(err error) *Message

NewErrorMessage creates an error message.

func NewErrorNotSupportedMessage added in v1.4.0

func NewErrorNotSupportedMessage(cmd string) *Message

NewErrorNotSupportedMessage returns a new ErrNotSupported message.

func NewFloatMessage added in v1.1.0

func NewFloatMessage(val float64) *Message

NewFloatMessage creates an float message.

func NewIntegerMessage

func NewIntegerMessage(val int) *Message

NewIntegerMessage creates an integer message.

func NewNilMessage

func NewNilMessage() *Message

NewNilMessage creates a nil bulk string message.

func NewOKMessage

func NewOKMessage() *Message

NewOKMessage creates a OK string message.

func NewStringArrayMessage added in v1.0.0

func NewStringArrayMessage(strs []string) *Message

NewStringArrayMessage creates an array message with the specified strings.

func NewStringMessage

func NewStringMessage(msg string) *Message

NewStringMessage creates a string message.

type PushOption added in v1.1.0

type PushOption struct {
	X bool
}

type RenameOption added in v1.0.0

type RenameOption struct {
	NX bool
}

type ScanOption added in v1.4.3

type ScanOption struct {
	MatchPattern *glob.Glob
	Count        int
	Type         ScanType
}

type ScanType added in v1.4.3

type ScanType int
const (
	KeyScan ScanType = iota
	SetScan
	HashScan
	SortedSetScan
)

type Server

type Server struct {
	*ServerConfig
	*auth.AuthManager
	*ConnManager
	tracer.Tracer
	Addr string
	// contains filtered or unexported fields
}

Server is an instance for Redis protocols.

func NewServer

func NewServer() *Server

NewServer returns a new server instance.

func (*Server) Auth added in v1.4.0

func (server *Server) Auth(conn *Conn, username string, password string) (*Message, error)

func (*Server) ConfigGet added in v1.2.0

func (server *Server) ConfigGet(conn *Conn, keys []string) (*Message, error)

func (*Server) ConfigSet added in v1.2.0

func (server *Server) ConfigSet(conn *Conn, params map[string]string) (*Message, error)

func (*Server) Echo

func (server *Server) Echo(conn *Conn, arg string) (*Message, error)

func (*Server) Ping

func (server *Server) Ping(conn *Conn, arg string) (*Message, error)

func (*Server) Quit

func (server *Server) Quit(conn *Conn) (*Message, error)

func (*Server) RegisterExexutor added in v1.0.0

func (server *Server) RegisterExexutor(cmd string, executor Executor)

RegisterExexutor sets a command executor.

func (*Server) Restart

func (server *Server) Restart() error

Restart restarts the server.

func (*Server) Select

func (server *Server) Select(conn *Conn, index int) (*Message, error)

func (*Server) SetAuthCommandHandler added in v1.4.0

func (server *Server) SetAuthCommandHandler(handler AuthCommandHandler)

SetAuthCommandHandler sets a auth handler to handle auth commands.

func (*Server) SetCommandHandler

func (server *Server) SetCommandHandler(handler UserCommandHandler)

SetCommandHandler sets a user handler to handle user commands.

func (*Server) SetTracer added in v1.3.2

func (server *Server) SetTracer(t tracer.Tracer)

SetTracer sets a tracing tracer.

func (*Server) Start

func (server *Server) Start() error

Start starts the server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stops the server.

type ServerConfig added in v1.4.0

type ServerConfig struct {
	*Config
	ServerCert []byte
	ServerKey  []byte
	CACerts    []byte
	TLSConfig  *tls.Config
}

ServerConfig is a configuration for the Redis server.

func NewDefaultServerConfig added in v1.4.0

func NewDefaultServerConfig() *ServerConfig

NewDefaultServerConfig returns a default server configuration.

func (*ServerConfig) ConfigPort added in v1.4.0

func (cfg *ServerConfig) ConfigPort() int

ConfigPort returns a listen port number.

func (*ServerConfig) ConfigRequirePass added in v1.4.0

func (cfg *ServerConfig) ConfigRequirePass() (string, bool)

ConfigRequirePass returns a password.

func (*ServerConfig) ConfigTLSCACert added in v1.5.1

func (cfg *ServerConfig) ConfigTLSCACert() ([]byte, bool)

ConfigTLSCACert returns a CA certificate.

func (*ServerConfig) ConfigTLSCACertFile added in v1.5.1

func (cfg *ServerConfig) ConfigTLSCACertFile() (string, bool)

ConfigTLSCACertFile returns a CA certificate file.

func (*ServerConfig) ConfigTLSCert added in v1.5.1

func (cfg *ServerConfig) ConfigTLSCert() ([]byte, bool)

ConfigTLSCert returns a certificate.

func (*ServerConfig) ConfigTLSCertFile added in v1.5.0

func (cfg *ServerConfig) ConfigTLSCertFile() (string, bool)

ConfigTLSCertFile returns a certificate file.

func (*ServerConfig) ConfigTLSConfig added in v1.5.1

func (cfg *ServerConfig) ConfigTLSConfig() (*tls.Config, bool)

ConfigTLSConfig returns a TLS configuration.

func (*ServerConfig) ConfigTLSKey added in v1.5.1

func (cfg *ServerConfig) ConfigTLSKey() ([]byte, bool)

ConfigTLSKey returns a key.

func (*ServerConfig) ConfigTLSKeyFile added in v1.5.0

func (cfg *ServerConfig) ConfigTLSKeyFile() (string, bool)

ConfigTLSKeyFile returns a key file.

func (*ServerConfig) ConfigTLSPort added in v1.5.0

func (cfg *ServerConfig) ConfigTLSPort() int

ConfigTLSPort returns a listen port number for TLS.

func (*ServerConfig) IsPortEnabled added in v1.5.0

func (cfg *ServerConfig) IsPortEnabled() bool

IsPortEnabled returns true if a listen port is enabled.

func (*ServerConfig) IsTLSPortEnabled added in v1.5.0

func (cfg *ServerConfig) IsTLSPortEnabled() bool

IsTLSPortEnabled returns true if a listen port for TLS is enabled.

func (*ServerConfig) RemoveRequirePass added in v1.4.0

func (cfg *ServerConfig) RemoveRequirePass()

RemoveRequirePass removes a password.

func (*ServerConfig) SetPort added in v1.4.0

func (cfg *ServerConfig) SetPort(port int)

SetPort sets a listen port number.

func (*ServerConfig) SetRequirePass added in v1.4.0

func (cfg *ServerConfig) SetRequirePass(password string)

SetRequirePass sets a password.

func (*ServerConfig) SetTLSCaCertFile added in v1.5.0

func (cfg *ServerConfig) SetTLSCaCertFile(caCertFile string) error

SetTLSCaCertFile sets a CA certificate file.

func (*ServerConfig) SetTLSCertFile added in v1.5.0

func (cfg *ServerConfig) SetTLSCertFile(certFile string) error

SetTLSCertFile sets a certificate file.

func (*ServerConfig) SetTLSConfig added in v1.5.1

func (cfg *ServerConfig) SetTLSConfig(tlsConfig *tls.Config)

SetTLSConfig sets a TLS configuration.

func (*ServerConfig) SetTLSKeyFile added in v1.5.0

func (cfg *ServerConfig) SetTLSKeyFile(keyFile string) error

SetTLSKeyFile sets a key file.

func (*ServerConfig) SetTLSPort added in v1.5.0

func (cfg *ServerConfig) SetTLSPort(port int)

SetTLSPort sets a listen port number for TLS.

type ServerManagementCommandHandler added in v1.2.0

type ServerManagementCommandHandler interface {
	ConfigSet(conn *Conn, params map[string]string) (*Message, error)
	ConfigGet(conn *Conn, keys []string) (*Message, error)
}

ServerManagementCommandHandler represents a hander interface for server management commands.

type SetCommandHandler added in v1.1.0

type SetCommandHandler interface {
	SAdd(conn *Conn, key string, members []string) (*Message, error)
	SMembers(conn *Conn, key string) (*Message, error)
	SRem(conn *Conn, key string, members []string) (*Message, error)
}

SetCommandHandler represents a core command hander interface for set commands.

type SetOption

type SetOption struct {
	EX      time.Duration
	PX      time.Duration
	EXAT    time.Time
	PXAT    time.Time
	NX      bool
	XX      bool
	KEEPTTL bool
	GET     bool
}

type StringCommandHandler added in v1.0.0

type StringCommandHandler interface {
	// Set represents a handler interface for SET, SETNX, SETEX, PSETEX, MSET and MSETNX commands.
	Set(conn *Conn, key string, val string, opt SetOption) (*Message, error)
	// Get represents a handler interface for GET and MGET commands.
	Get(conn *Conn, key string) (*Message, error)
}

StringCommandHandler represents a core command hander interface for string commands. APPEND, DECR, DECRBY, GETRANGE, GETSET, INCR, INCRBY, MGET, MSET, MSETNX, SETRANGE, STRLEN commands are implemented by the StringCommandHandler.

type SystemCommandHandler

type SystemCommandHandler interface {
	ConnectionManagementCommandHandler
	ServerManagementCommandHandler
}

SystemCommandHandler represents a hander interface for system commands.

type UserCommandHandler added in v1.1.0

UserCommandHandler represents a command hander interface for user commands.

type ZAddOption added in v1.1.0

type ZAddOption struct {
	XX   bool
	NX   bool
	LT   bool
	GT   bool
	CH   bool
	INCR bool
}

type ZRangeOption added in v1.1.0

type ZRangeOption struct {
	BYSCORE      bool
	BYLEX        bool
	REV          bool
	WITHSCORES   bool
	MINEXCLUSIVE bool
	MAXEXCLUSIVE bool
	Offset       int
	Count        int
}

type ZSetCommandHandler added in v1.1.0

type ZSetCommandHandler interface {
	ZAdd(conn *Conn, key string, members []*ZSetMember, opt ZAddOption) (*Message, error)
	ZRange(conn *Conn, key string, start int, stop int, opt ZRangeOption) (*Message, error)
	ZRangeByScore(conn *Conn, key string, min float64, max float64, opt ZRangeOption) (*Message, error)
	ZRem(conn *Conn, key string, members []string) (*Message, error)
	ZScore(conn *Conn, key string, member string) (*Message, error)
	ZIncBy(conn *Conn, key string, inc float64, member string) (*Message, error)
}

ZSetCommandHandler represents a core command hander interface for zset commands.

type ZSetMember added in v1.1.0

type ZSetMember struct {
	Score  float64
	Member string
}

ZSetMember represents a parameter for ZSetCommandHandler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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