This is a simple memcached server written in Go. Supports only set & get operations as of now.
$ go get github.com/vbellur/memcached-go/cmd/memcached
After this operation, source code will be located in:
$GOPATH/src/github.com/vbellur/memcached-go/cmd/memcached
From this directory, the following command can be issued to build the binary:
$go build .
memcached-go provides a LRU cache that can be accessed using get
and set
commands over the memcached ascii protocol. The LRU is maintained using a combination of:
- Doubly Linked List (DLL) containing nodes that have key, value and other metadata.
- Map of keys to pointers for nodes in the DLL.
A set operation results in both the DLL and map being updated. An existing key's value gets updated during a set or a new key is added to the cache. If the cache is full, the node at the tail of the DLL is evicted to make space for the new key, value tuple.
A get operation causes the node pertaining to the key to be promoted to the head of the list.
By default, the maximum number of keys in the cache is 10000. This can be altered by changing the value passed to CacheInit()
in memcached.go
.
When a connection is established from the client, a goroutine is used to manage the connection and commands that are issued over the connection by the client.
The memcached
binary generated after go build
can be started using:
$memcached
This will launch a foreground process that will run on port 11211 by default. In case, you need to run the server on a different port, please specify the port as an argument to memcached, like:
$memcached 9001
Once the server is up and running, you can use your favorite memcached client tool/interface to work with the server.
There are two categories of tests provided with the source:
- Unit tests - These can be run using
go test -v
in the memcached directory. - Functional tests - There are functional tests in the tests/ directory. Currently, there are two test units: a> mctest.go - Runs a bunch of set and get tests & also verifies data integrity by hash comparison. b>conmctest.go - Runs concurrent sets and gets using goroutines.
Both these test units utilize gomemcache client library for running tests and gomemcache will need to be installed on your system before these tests are run. Both test units talk to a single instance of the memcached server by default.
- Authentication is not supported with
set
command as of yet. - flags, exptime and noreply are ignored by the server.
- Segmented LRU is not yet supported.
- memcached is reachable only over TCP. There is no support for UDP.
- LRU eviction happens only when the cache capacity is full. Other schemes like eviction based on size, etc. are not yet available.
- verbose mode for logging is not yet available.
Please use github issues for reporting bugs & issues observed.