Memcached protocol implementation for memcached server. You can use it to create a memcached server easily.
import this lib:
go get -u github.com/rpcxio/gomemcached
And register handlers.
addr := "127.0.0.1:" + strconv.Itoa(port)
// or use unix domain socket, like:
// addr := "unix:///tmp/memcached.sock"
mockServer := NewServer(addr)
mockServer.RegisterFunc("get", DefaultGet)
mockServer.RegisterFunc("gets", DefaultGet)
mockServer.RegisterFunc("set", DefaultSet)
mockServer.RegisterFunc("delete", DefaultDelete)
mockServer.RegisterFunc("incr", DefaultIncr)
mockServer.RegisterFunc("flush_all", DefaultFlushAll)
mockServer.RegisterFunc("version", DefaultVersion)
mockServer.Start()
This project refers to the below projects:
I added more implementation and fix some issues, for example, panic on reading long value. I also add Context
in handlers so that we can pass more info to handlers.