Documentation
¶
Overview ¶
Package server implements a redis server
Example ¶
package main
import (
"log"
"net"
"github.com/Akagi201/redface/resp"
"github.com/Akagi201/redface/server"
)
var pongSS = resp.NewRespSimple("PONG")
func pingHandler(conn net.Conn, args []string) (interface{}, error) {
return pongSS, nil
}
func main() {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v\n", err)
}
}()
srv, err := server.New(6389)
if err != nil {
panic(err)
}
srv.Handle("ping", pingHandler)
if err := srv.ListenAndServe(); err != nil {
panic(err)
}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type Opts ¶
type Opts struct {
// "unix" for unix socket, "tcp" for tcp
Proto string
// The address to listen at
Host string
// The port to listen at
Port int
}
Opts are Options which can be passed in to NewWithOpts. If any are set to their zero value the default value will be used instead
type Server ¶
type Server struct {
// "unix" for unix socket, "tcp" for tcp
Proto string
// TCP address to listen on, ":6379" if empty
Addr string
// contains filtered or unexported fields
}
Server A Server defines parameters for running an Redis API Server. The zero value for Server is a valid configuration.
func NewWithOpts ¶
NewWithOpts is the same as New, but with more fine-tuned configuration options. See Opts for more available options.
func (*Server) Dispatch ¶
Dispatch takes in a client whose command has already been read off the socket, a list of arguments from that command (not including the command name itself), and handles that command
func (*Server) Handle ¶
func (srv *Server) Handle(cmd string, handlerFunc HandlerFunc)
Handle registers the handler for the given cmd. If a handler already exists for pattern, Handle panics.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP or Unix socket network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":6379" is used. ListenAndServe always returns a non-nil error.