server

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 Client

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

func NewClient

func NewClient(c *config.Client) *Client

func (*Client) Addresses

func (c *Client) Addresses() map[string]struct{}

func (*Client) Close

func (c *Client) Close(addr string) error

func (*Client) Get

func (c *Client) Get(addr string) *redis.Client

func (*Client) Pick

func (c *Client) Pick() (*redis.Client, error)

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

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

type ConnWrapper struct {
	net.Conn
}

ConnWrapper is a wrapper around net.Conn that enables tracking of read and written bytes.

func (*ConnWrapper) Read

func (cw *ConnWrapper) Read(b []byte) (n int, err error)

Read reads data into the provided byte slice, updates the read bytes counter, and returns the number of bytes read.

func (*ConnWrapper) Write

func (cw *ConnWrapper) Write(b []byte) (n int, err error)

Write sends data over the underlying connection and updates the total written bytes counter. It returns the number of bytes written and any error encountered.

type Handler

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

func (Handler) ServeRESP

func (h Handler) ServeRESP(conn redcon.Conn, cmd redcon.Command)

ServeRESP calls f(w, r)

type HandlerFunc

type HandlerFunc func(conn redcon.Conn, cmd redcon.Command)

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

type ListenerWrapper struct {
	net.Listener
	// contains filtered or unexported fields
}

ListenerWrapper is a wrapper around net.Listener that supports setting a TCP keep-alive period for accepted connections.

func (*ListenerWrapper) Accept

func (lw *ListenerWrapper) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the ListenerWrapper, applying TCP keep-alive settings if specified.

type ServeMux

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

ServeMux is an RESP command multiplexer.

func NewServeMux

func NewServeMux(c *Config) *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (m *ServeMux) Handle(command string, handler redcon.Handler)

Handle registers the handler for the given command. If a handler already exists for command, Handle panics.

func (*ServeMux) HandleFunc

func (m *ServeMux) HandleFunc(command string, handler redcon.Handler)

HandleFunc registers the handler function for the given command.

func (*ServeMux) ServeRESP

func (m *ServeMux) ServeRESP(conn redcon.Conn, cmd redcon.Command)

ServeRESP dispatches the command to the handler.

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

type Server struct {
	StartedCtx context.Context
	// contains filtered or unexported fields
}

Server is a TCP server struct that manages configurations, logging, and connection handling for RESP-based protocols.

func New

func New(c *Config, l *flog.Logger) *Server

New initializes and returns a new Server configured with the specified Config and Logger.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the TCP server, initializes internal components, and begins accepting connections.

func (*Server) ServeMux

func (s *Server) ServeMux() *ServeMuxWrapper

func (*Server) SetPreConditionFunc

func (s *Server) SetPreConditionFunc(f func(conn redcon.Conn, cmd redcon.Command) bool)

SetPreConditionFunc sets a precondition function to be executed before serving each command on the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

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).

Jump to

Keyboard shortcuts

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