server

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommandsTotal is total number of all requests broken down by command (get, put, etc.) and status.
	CommandsTotal = stats.NewInt64Counter()

	// ConnectionsTotal is total number of connections opened since the server started running.
	ConnectionsTotal = stats.NewInt64Counter()

	// CurrentConnections is current number of open connections.
	CurrentConnections = stats.NewInt64Gauge()

	// WrittenBytesTotal is total number of bytes sent by this server to network.
	WrittenBytesTotal = stats.NewInt64Counter()

	// ReadBytesTotal is 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
}

Config is a composite type to bundle configuration parameters.

type ConnWrapper

type ConnWrapper struct {
	net.Conn
}

func (*ConnWrapper) Read

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

func (*ConnWrapper) Write

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

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
}

func (*ListenerWrapper) Accept

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

type ServeMux

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

ServeMux is an RESP command multiplexer.

func NewServeMux

func NewServeMux() *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
}

func New

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

New creates and returns a new Server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address addr.

func (*Server) ServeMux

func (s *Server) ServeMux() *ServeMuxWrapper

func (*Server) SetPreConditionFunc

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

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