Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // CommandsTotal is the total number of all requests broken down by command (get, put, etc.) and status. CommandsTotal = stats.NewInt64Counter() // ConnectionsTotal is the total number of connections opened since the server started running. ConnectionsTotal = stats.NewInt64Counter() // CurrentConnections is the current number of open connections. CurrentConnections = stats.NewInt64Gauge() // WrittenBytesTotal is the total number of bytes sent by this server to network. WrittenBytesTotal = stats.NewInt64Counter() // ReadBytesTotal is the total number of bytes read by this server from network. ReadBytesTotal = stats.NewInt64Counter() )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { BindAddr string BindPort int KeepAlivePeriod time.Duration IdleClose time.Duration RequireAuth bool }
Config is a composite type to bundle configuration parameters.
type ConnContext ¶ added in v0.7.0
type ConnContext struct {
// contains filtered or unexported fields
}
ConnContext represents the context for a connection with authentication state management.
func NewConnContext ¶ added in v0.7.0
func NewConnContext() *ConnContext
NewConnContext initializes and returns a new instance of ConnContext for managing connection states like authentication.
func (*ConnContext) IsAuthenticated ¶ added in v0.7.0
func (c *ConnContext) IsAuthenticated() bool
IsAuthenticated checks if the connection is authenticated. It is thread-safe and returns true if authenticated.
func (*ConnContext) SetAuthenticated ¶ added in v0.7.0
func (c *ConnContext) SetAuthenticated(authenticated bool)
SetAuthenticated sets the authentication state of the connection to the specified value. It is thread-safe.
type ConnWrapper ¶
ConnWrapper is a wrapper around net.Conn that enables tracking of read and written bytes.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as RESP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type ListenerWrapper ¶
ListenerWrapper is a wrapper around net.Listener that supports setting a TCP keep-alive period for accepted connections.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is an RESP command multiplexer.
func NewServeMux ¶
NewServeMux allocates and returns a new ServeMux.
func (*ServeMux) Handle ¶
Handle registers the handler for the given command. If a handler already exists for command, Handle panics.
func (*ServeMux) HandleFunc ¶
HandleFunc registers the handler function for the given command.
type ServeMuxWrapper ¶
type ServeMuxWrapper struct {
// contains filtered or unexported fields
}
func (*ServeMuxWrapper) HandleFunc ¶
func (m *ServeMuxWrapper) HandleFunc(command string, handler func(conn redcon.Conn, cmd redcon.Command))
HandleFunc registers the handler function for the given command.
type Server ¶
Server is a TCP server struct that manages configurations, logging, and connection handling for RESP-based protocols.
func New ¶
New initializes and returns a new Server configured with the specified Config and Logger.
func (*Server) ListenAndServe ¶
ListenAndServe starts the TCP server, initializes internal components, and begins accepting connections.
func (*Server) ServeMux ¶
func (s *Server) ServeMux() *ServeMuxWrapper
func (*Server) SetPreConditionFunc ¶
SetPreConditionFunc sets a precondition function to be executed before serving each command on the server.
func (*Server) Shutdown ¶
Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error; otherwise it returns any error returned from closing the Server's underlying Listener(s).