server

package
v2.21.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProtocol = errors.New("invalid request")

ErrProtocol is the general error for unexpected input

Functions

func ParseReply added in v2.11.2

func ParseReply(rd *bufio.Reader) (interface{}, error)

parse a reply

Types

type Cmd

type Cmd func(c *Peer, cmd string, args []string)

Cmd is what Register expects

type DisconnectHandler

type DisconnectHandler func(c *Peer)

type Hook added in v2.13.0

type Hook func(*Peer, string, ...string) bool

Hook is can be added to run before every cmd. Return true if the command is done.

type Peer

type Peer struct {
	Resp3 bool
	Ctx   interface{} // anything goes, server won't touch this
	// contains filtered or unexported fields
}

Peer is a client connected to the server

func NewPeer added in v2.11.2

func NewPeer(w *bufio.Writer) *Peer

func (*Peer) Block

func (c *Peer) Block(f func(*Writer))

issue multiple calls, guarded with a mutex

func (*Peer) Close

func (c *Peer) Close()

Close the client connection after the current command is done.

func (*Peer) Flush

func (c *Peer) Flush()

Flush the write buffer. Called automatically after every redis command

func (*Peer) OnDisconnect

func (c *Peer) OnDisconnect(f func())

Register a function to execute on disconnect. There can be multiple functions registered.

func (*Peer) WriteBulk

func (c *Peer) WriteBulk(s string)

WriteBulk writes a bulk string

func (*Peer) WriteError

func (c *Peer) WriteError(e string)

WriteError writes a redis 'Error'

func (*Peer) WriteFloat added in v2.14.0

func (c *Peer) WriteFloat(n float64)

WriteFloat writes a float

func (*Peer) WriteInline

func (c *Peer) WriteInline(s string)

WriteInline writes a redis inline string

func (*Peer) WriteInt

func (c *Peer) WriteInt(n int)

WriteInt writes an integer

func (*Peer) WriteLen

func (c *Peer) WriteLen(n int)

WriteLen starts an array with the given length

func (*Peer) WriteMapLen added in v2.14.0

func (c *Peer) WriteMapLen(n int)

WriteMapLen starts a map with the given length (number of keys)

func (*Peer) WriteNull

func (c *Peer) WriteNull()

WriteNull writes a redis Null element

func (*Peer) WriteOK

func (c *Peer) WriteOK()

WriteOK write the inline string `OK`

func (*Peer) WritePushLen added in v2.14.0

func (c *Peer) WritePushLen(n int)

WritePushLen starts a push-data array with the given length

func (*Peer) WriteRaw added in v2.11.3

func (c *Peer) WriteRaw(s string)

WriteRaw writes a raw redis response

func (*Peer) WriteSetLen added in v2.14.0

func (c *Peer) WriteSetLen(n int)

WriteSetLen starts a set with the given length (number of elements)

func (*Peer) WriteStrings added in v2.15.0

func (c *Peer) WriteStrings(strs []string)

WriteStrings is a helper to (bulk)write a string list

type Server

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

Server is a simple redis server

func NewServer

func NewServer(addr string) (*Server, error)

NewServer makes a server listening on addr. Close with .Close().

func NewServerTLS added in v2.13.0

func NewServerTLS(addr string, cfg *tls.Config) (*Server, error)

func (*Server) Addr

func (s *Server) Addr() *net.TCPAddr

Addr has the net.Addr struct

func (*Server) ClientsLen

func (s *Server) ClientsLen() int

ClientsLen gives the number of connected clients right now

func (*Server) Close

func (s *Server) Close()

Close a server started with NewServer. It will wait until all clients are closed.

func (*Server) Dispatch added in v2.11.2

func (s *Server) Dispatch(c *Peer, args []string)

func (*Server) Register

func (s *Server) Register(cmd string, f Cmd) error

Register a command. It can't have been registered before. Safe to call on a running server.

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn handles a net.Conn. Nice with net.Pipe()

func (*Server) SetPreHook added in v2.13.0

func (s *Server) SetPreHook(h Hook)

(un)set a hook which is ran before every call. It returns true if the command is done.

func (*Server) TotalCommands

func (s *Server) TotalCommands() int

TotalCommands is total (known) commands since this the server started

func (*Server) TotalConnections

func (s *Server) TotalConnections() int

TotalConnections give the number of clients connected since the server started, including the currently connected ones

type Simple added in v2.19.0

type Simple string

type Writer

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

A Writer is given to the callback in Block()

func (*Writer) Flush

func (w *Writer) Flush()

func (*Writer) WriteBulk

func (w *Writer) WriteBulk(s string)

WriteBulk writes a bulk string

func (*Writer) WriteError

func (w *Writer) WriteError(e string)

WriteError writes a redis 'Error'

func (*Writer) WriteFloat added in v2.14.0

func (w *Writer) WriteFloat(n float64)

WriteFloat writes a float

func (*Writer) WriteInline

func (w *Writer) WriteInline(s string)

WriteInline writes a redis inline string

func (*Writer) WriteInt

func (w *Writer) WriteInt(n int)

WriteInt writes an integer

func (*Writer) WriteLen

func (w *Writer) WriteLen(n int)

func (*Writer) WriteMapLen added in v2.14.0

func (w *Writer) WriteMapLen(n int)

func (*Writer) WriteNull

func (w *Writer) WriteNull()

WriteNull writes a redis Null element

func (*Writer) WritePushLen added in v2.14.0

func (w *Writer) WritePushLen(n int)

func (*Writer) WriteRaw added in v2.11.3

func (w *Writer) WriteRaw(s string)

WriteRaw writes a raw redis response

func (*Writer) WriteSetLen added in v2.14.0

func (w *Writer) WriteSetLen(n int)

func (*Writer) WriteStrings added in v2.15.0

func (w *Writer) WriteStrings(strs []string)

WriteStrings writes a list of strings (bulk)

Jump to

Keyboard shortcuts

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