server

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 8 Imported by: 0

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

This section is empty.

Types

type Cmd

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

Cmd is what Register expects

type Peer

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

Peer is a client connected to the server

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

func (c *Peer) WriteInline(s string)

WriteInline writes a redis inline string

func (*Peer) WriteInt

func (c *Peer) WriteInt(i int)

WriteInt writes an integer

func (*Peer) WriteLen

func (c *Peer) WriteLen(n int)

WriteLen starts an array with the given length

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`

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 (*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) 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) 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

Jump to

Keyboard shortcuts

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