/gomemcache

Go Memcached client library #golang

Primary LanguageGoApache License 2.0Apache-2.0

About

This is a memcache client library for the Go programming language (http://golang.org/).

Installing

Using go get

$ go get github.com/bradfitz/gomemcache/memcache

After this command gomemcache is ready to use. Its source will be in:

$GOPATH/src/github.com/bradfitz/gomemcache/memcache

Example

import (
        "github.com/bradfitz/gomemcache/memcache"
)

func main() {
     mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
     mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})

     it, err := mc.Get("foo")
     ...
}

Example using with app engine

import (
        "github.com/bradfitz/gomemcache/memcache"
)

func index(w http.ResponseWriter, r *http.Request) {
    dialer := func(net, addr string, timeout time.Duration) (net.Conn, error) {
	    return socket.Dial(appengine.NewContext(r), "tcp", addr)
	}
    memcache.RegisterDial("ext", dialer)

    mc := memcache.New("ext://10.0.0.1:11211", "ext://10.0.0.2:11211", "ext://10.0.0.3:11212")
    ...
}

func main() {
    http.Handle("/", index)
}

Full docs, see:

See https://godoc.org/github.com/bradfitz/gomemcache/memcache

Or run:

$ godoc github.com/bradfitz/gomemcache/memcache