MC - short for Memory Cache - is a simple distributed caching server for learning purpose.
- In memory LRU cache
- RPC transport
- Cluster
- Command line client
- Go client
So far, MC has only get
, add
and remove
of caching and a Consistent Hash Algorithm will be considered to use for the scalability in the future.
go get github.com/mivinci/mc
Or (not available yet)
docker pull mivinci/mc
Or download the pre-build version for macOS or Windows.
mc
can be run either a server or a client.
mc -server
By default, MC chooses 127.0.0.1:8000
to serve on, or you can decide the address by providing a -address
parameter.
mc -server -address 127.0.0.1:8001
for short
mc -server -address :8001
You can customize the maximum caching size for a single MC server.
mc -server -c 128
mc -client
Also, the MC client chooses 127.0.0.1:8000
to dial during usage. You can provide an -address
parameter to the MC client to communicate with a different address.
Once you have run multiple MC servers, you can communicate with them simply by using the MC client with multiple addresses seperated by commas.
mc -client -address 1.1.1.1:8000,1.1.1.2:8001,1.1.1.3:8002
The MC command line client will lead you to an interface like this.
$ mc -client
MC v1.0.0, press [ctrl c] to exit.
127.0.0.1:8000> get name
XJJ
127.0.0.1:8000> remove name
127.0.0.1:8000> get name
nil
import "github.com/mivinci/mc"
r := mc.Add("name", []byte("XJJ"))
r := mc.Get("name")
r := mc.Remove("name")
client := mc.NewClient("1.1.1.1:8000", "1.1.1.2:8001", "1.1.1.3:8000")
r := client.Get("name")
...
Thanks to the projects and videos below for the inspiration.