redis

package
v0.0.0-...-ce0549f Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerContextKey    = &contextKey{"redis-server"}
	LocalAddrContextKey = &contextKey{"local-addr"}

	ErrServerClosed = errors.New("redis: Server closed")
)
View Source
var (
	DefaultServeMux = &defaultServeMux
)

Functions

func HandleFunc

func HandleFunc(pattern string, handler func(context.Context, ResponseWriter, *Request))

func ListenAndServe

func ListenAndServe(addr string, handler Handler, opts ...Option) error

func NotFound

func NotFound(ctx context.Context, w ResponseWriter, r *Request)

Types

type ConnState

type ConnState int
const (
	// StateNew represents a new connection that is expected to
	// send a request immediately. Connections begin at this
	// state and then transition to either StateActive or
	// StateClosed.
	StateNew ConnState = iota

	// StateActive represents a connection that has read 1 or more
	// bytes of a request. The Server.ConnState hook for
	// StateActive fires before the request has entered a handler
	// and doesn't fire again until the request has been
	// handled. After the request is handled, the state
	// transitions to StateClosed, StateHijacked, or StateIdle.
	// For HTTP/2, StateActive fires on the transition from zero
	// to one active request, and only transitions away once all
	// active requests are complete. That means that ConnState
	// cannot be used to do per-request work; ConnState only notes
	// the overall state of the connection.
	StateActive

	// StateIdle represents a connection that has finished
	// handling a request and is in the keep-alive state, waiting
	// for a new request. Connections transition from StateIdle
	// to either StateActive or StateClosed.
	StateIdle

	// StateHijacked represents a hijacked connection.
	// This is a terminal state. It does not transition to StateClosed.
	StateHijacked

	// StateClosed represents a closed connection.
	// This is a terminal state. Hijacked connections do not
	// transition to StateClosed.
	StateClosed
)

func (ConnState) String

func (c ConnState) String() string

type Handler

type Handler interface {
	ServeRedis(context.Context, ResponseWriter, *Request)
}

func NotFoundHandler

func NotFoundHandler() Handler

type HandlerFunc

type HandlerFunc func(context.Context, ResponseWriter, *Request)

func MergeMiddleware

func MergeMiddleware(fn HandlerFunc, middlewares ...MiddlewareFunc) HandlerFunc

func (HandlerFunc) ServeRedis

func (f HandlerFunc) ServeRedis(ctx context.Context, w ResponseWriter, r *Request)

type Logger

type Logger interface {
	Debug(string, ...interface{})
	Info(string, ...interface{})
	Notice(string, ...interface{})
	Warn(string, ...interface{})
	Error(string, ...interface{})

	AddMeta(string, string)
}

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

type Option

type Option func(*option)

func WithLoggerFactory

func WithLoggerFactory(genFn func() Logger) Option

func WithPanicStack

func WithPanicStack(fn func(string, ...interface{})) Option

func WithSemaphore

func WithSemaphore(s *Semaphore) Option

type Request

type Request struct {
	Cmd  string
	Args []string
	// contains filtered or unexported fields
}

func (*Request) Logger

func (r *Request) Logger() Logger

func (*Request) Remote

func (r *Request) Remote() string

type ResponseWriter

type ResponseWriter interface {
	Error(string, ...interface{}) (int, error)
	Text(string, ...interface{}) (int, error)
	Binary([]byte) (int, error)

	Write([]byte) (int, error)
}

type SemaOpt

type SemaOpt func(*semaOpt)

func WithBlock

func WithBlock(block bool) SemaOpt

func WithWaitDura

func WithWaitDura(d time.Duration) SemaOpt

if block is false, this config should not be used

type Semaphore

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

func NewSemaphore

func NewSemaphore(n int64, opts ...SemaOpt) (*Semaphore, error)

type ServeMux

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

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler Handler)

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(context.Context, ResponseWriter, *Request), middlewares ...MiddlewareFunc)

func (*ServeMux) ServeRedis

func (mux *ServeMux) ServeRedis(ctx context.Context, w ResponseWriter, r *Request)

type Server

type Server struct {
	Addr    string
	Handler Handler

	ConnState func(net.Conn, ConnState)
	// contains filtered or unexported fields
}

func (*Server) Close

func (srv *Server) Close() error

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(opts ...Option) error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener, opts ...Option) error

func (*Server) Shutdown

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

Jump to

Keyboard shortcuts

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