memcached

package module
v0.0.0-...-a052bcb Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 15 Imported by: 0

README

Go Memcache Server

A Go implementation of the memcached protocol, designed to be easy to switch storage mechanisms depending on your specific needs.

Usage

import (
  "log"

  "github.com/bradberger/memcached"
)

func main() {
  log.Fatal(memcached.ListenAndServe(":11211"))
}

Configuration

You can configure the storage engine, the listening address, and the logging interface. The server currently implements a subset of the memcached protocol. The extent to which it implements all the storage methods are dependent on the storage engine you choose. (I'll add details about what this means in the future)

import (
  "log"

  "github.com/bradberger/memcached"
  "github.com/bradberger/gocache/drivers/lru"
)

func main() {

  srv := &memcached.Server{
    // Set the cache engine.
    // Must implement "github.com/bradberger/gocache/cache.Cache" interface.
    Cache:  lru.NewBasic(lru.Gigabyte, 100000),
    // Set the logger.
    // Must implement "github.com/bradberger/memcached".Logger interface.
    Logger: logger.Init("Memcached", true, false, os.Stdout),
    // Set the listen address. Default is :11211
    Addr:   ":11211",
  }

  log.Fatal(srv.ListenAndServe())
}

TODO

  • increment command support
  • decrement command support
  • touch command support
  • [-] append command support
  • [-] prepend command support
  • gat command support
  • gats command support
  • cas command support
  • UDP support
  • Binary protocol support
  • handle noreply properly

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrInvalidCommand = errors.New("invalid command")
	ErrUnknownCommand = errors.New("unknown command")
)

Generic memcached errors

Functions

func ListenAndServe

func ListenAndServe(addr string) error

ListenAndServe starts a memcache server on the

Types

type Logger

type Logger interface {
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Errorln(v ...interface{})

	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Infoln(v ...interface{})

	Warning(v ...interface{})
	Warningf(format string, v ...interface{})
	Warningln(v ...interface{})

	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
}

type Server

type Server struct {
	Logger Logger
	Cache  cache.Cache
	Addr   string
}

Server defines parameters for running a memcache server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the configured network address and then calls Serve to handle memcache requests

func (*Server) Serve

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

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each.

Jump to

Keyboard shortcuts

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