Documentation ¶
Index ¶
- Constants
- Variables
- func NewErrNotSupported(target string) error
- func NewTLSConfigFrom(config *ServerConfig) (*tls.Config, error)
- type Arguments
- type AuthCommandHandler
- type Config
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) Database() DatabaseID
- func (conn *Conn) IsAuthrized() bool
- func (conn *Conn) IsTLSConnection() bool
- func (conn *Conn) Password() (string, bool)
- func (conn *Conn) SetAuthrized(authrized bool)
- func (conn *Conn) SetDatabase(id DatabaseID)
- func (conn *Conn) SetPassword(password string)
- func (conn *Conn) SetSpanContext(span tracer.Context)
- func (conn *Conn) SetUserName(username string)
- func (conn *Conn) SpanContext() tracer.Context
- func (conn *Conn) TLSConnectionState() (*tls.ConnectionState, bool)
- func (conn *Conn) Timestamp() time.Time
- func (conn *Conn) UUID() uuid.UUID
- func (conn *Conn) UserName() (string, bool)
- type ConnManager
- func (mgr *ConnManager) AddConn(c *Conn)
- func (mgr *ConnManager) Close() error
- func (mgr *ConnManager) ConnByUUID(uuid uuid.UUID) (*Conn, bool)
- func (mgr *ConnManager) Conns() []*Conn
- func (mgr *ConnManager) RemoveConn(conn *Conn) error
- func (mgr *ConnManager) Start() error
- func (mgr *ConnManager) Stop() error
- type ConnectionManagementCommandHandler
- type DatabaseID
- type Executor
- type Executors
- type ExpireOption
- type GenericCommandHandler
- type HSetOption
- type HashCommandHandler
- type ListCommandHandler
- type Message
- func NewArrayMessage() *Message
- func NewArrayMessageWithArray(val *proto.Array) *Message
- func NewBulkMessage(msg string) *Message
- func NewErrorMessage(err error) *Message
- func NewErrorNotSupportedMessage(cmd string) *Message
- func NewFloatMessage(val float64) *Message
- func NewIntegerMessage(val int) *Message
- func NewNilMessage() *Message
- func NewOKMessage() *Message
- func NewStringArrayMessage(strs []string) *Message
- func NewStringMessage(msg string) *Message
- type PushOption
- type RenameOption
- type ScanOption
- type ScanType
- type Server
- func (server *Server) Auth(conn *Conn, username string, password string) (*Message, error)
- func (server *Server) ConfigGet(conn *Conn, keys []string) (*Message, error)
- func (server *Server) ConfigSet(conn *Conn, params map[string]string) (*Message, error)
- func (server *Server) Echo(conn *Conn, arg string) (*Message, error)
- func (server *Server) Ping(conn *Conn, arg string) (*Message, error)
- func (server *Server) Quit(conn *Conn) (*Message, error)
- func (server *Server) RegisterExexutor(cmd string, executor Executor)
- func (server *Server) Restart() error
- func (server *Server) Select(conn *Conn, index int) (*Message, error)
- func (server *Server) SetAuthCommandHandler(handler AuthCommandHandler)
- func (server *Server) SetCommandHandler(handler UserCommandHandler)
- func (server *Server) SetTracer(t tracer.Tracer)
- func (server *Server) Start() error
- func (server *Server) Stop() error
- type ServerConfig
- func (cfg *ServerConfig) ConfigPort() int
- func (cfg *ServerConfig) ConfigRequirePass() (string, bool)
- func (cfg *ServerConfig) ConfigTLSCACert() ([]byte, bool)
- func (cfg *ServerConfig) ConfigTLSCACertFile() (string, bool)
- func (cfg *ServerConfig) ConfigTLSCert() ([]byte, bool)
- func (cfg *ServerConfig) ConfigTLSCertFile() (string, bool)
- func (cfg *ServerConfig) ConfigTLSConfig() (*tls.Config, bool)
- func (cfg *ServerConfig) ConfigTLSKey() ([]byte, bool)
- func (cfg *ServerConfig) ConfigTLSKeyFile() (string, bool)
- func (cfg *ServerConfig) ConfigTLSPort() int
- func (cfg *ServerConfig) IsPortEnabled() bool
- func (cfg *ServerConfig) IsTLSPortEnabled() bool
- func (cfg *ServerConfig) RemoveRequirePass()
- func (cfg *ServerConfig) SetPort(port int)
- func (cfg *ServerConfig) SetRequirePass(password string)
- func (cfg *ServerConfig) SetTLSCaCertFile(caCertFile string) error
- func (cfg *ServerConfig) SetTLSCertFile(certFile string) error
- func (cfg *ServerConfig) SetTLSConfig(tlsConfig *tls.Config)
- func (cfg *ServerConfig) SetTLSKeyFile(keyFile string) error
- func (cfg *ServerConfig) SetTLSPort(port int)
- type ServerManagementCommandHandler
- type SetCommandHandler
- type SetOption
- type StringCommandHandler
- type SystemCommandHandler
- type UserCommandHandler
- type ZAddOption
- type ZRangeOption
- type ZSetCommandHandler
- type ZSetMember
Constants ¶
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 )
const (
ConfigSep = " "
)
const (
OK = "OK"
)
const (
Version = "v1.5.3"
)
Variables ¶
Functions ¶
func NewErrNotSupported ¶ added in v1.4.0
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 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
AppendConfig appends a specified parameter.
func (*Config) ConfigInteger ¶ added in v1.5.0
ConfigInteger returns the specified parameter as an integer.
func (*Config) ConfigString ¶ added in v1.5.0
ConfigString return the specified parameter.
func (*Config) RemoveConfig ¶ added in v1.4.0
RemoveConfig removes the specified parameter.
type Conn ¶ added in v1.3.0
Conn represents a database 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
IsAuthrized returns true if the connection is authrized.
func (*Conn) IsTLSConnection ¶ added in v1.5.2
IsTLSConnection return true if the connection is enabled TLS.
func (*Conn) Password ¶ added in v1.5.2
Password returns the password and true if the connection has the password.
func (*Conn) SetAuthrized ¶ added in v1.4.0
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
SetPassword sets the password to the connection.
func (*Conn) SetSpanContext ¶ added in v1.3.5
SetAuthrizedxt to the connection.
func (*Conn) SetUserName ¶ added in v1.5.2
SetUserName sets the user name to the connection.
func (*Conn) SpanContext ¶ added in v1.3.5
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.
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 ExpireOption ¶ added in v1.0.0
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 ¶
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
NewArrayMessageWithArray creates an array message with the specified array.
func NewBulkMessage ¶
NewBulkMessage creates a bulk string message.
func NewErrorMessage ¶
NewErrorMessage creates an error message.
func NewErrorNotSupportedMessage ¶ added in v1.4.0
NewErrorNotSupportedMessage returns a new ErrNotSupported message.
func NewFloatMessage ¶ added in v1.1.0
NewFloatMessage creates an float message.
func NewIntegerMessage ¶
NewIntegerMessage creates an integer message.
func NewStringArrayMessage ¶ added in v1.0.0
NewStringArrayMessage creates an array message with the specified strings.
func NewStringMessage ¶
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 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 (*Server) RegisterExexutor ¶ added in v1.0.0
RegisterExexutor sets a command executor.
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.
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 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
type UserCommandHandler interface { GenericCommandHandler StringCommandHandler HashCommandHandler ListCommandHandler SetCommandHandler ZSetCommandHandler }
UserCommandHandler represents a command hander interface for user commands.
type ZAddOption ¶ added in v1.1.0
type ZRangeOption ¶ added in v1.1.0
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
ZSetMember represents a parameter for ZSetCommandHandler.