gomemcache

module
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2022 License: Apache-2.0

README

About

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

Why this project?

The version is bumped to v3 to indicate that it has something incompatible with the vanilla one.

get vs gets

There are many derivate servers which implement incomplete memcache prototol, e.g. only get and set are implemented.

The thing is, the original repository of gomemcache has something confusing when it comes to get command.

if _, err := fmt.Fprintf(rw, "gets %s\r\n", strings.Join(keys, " ")); err != nil {
    return err
}

It means when you call get, the gets command is executed and casid is always returned.

dest := []interface{}{&it.Key, &it.Flags, &size, &it.casid}

I've talked to bradfitz and got a lot of important advises from him. Truly all the things I mentioned above are all because of the incomplete implementation and have nothing to do with the client. What I stand for is get means get and gets means gets.

RoundRobinServerSelector

Vanilla memcache server use crc32 to pick which server to store a key, for servers those distribute keys equally to all nodes the crc32 is not what is wanted. Thanks for bradfitz's brilliant work I can implement a RoundRobinServerSelector painlessly.

Installing

Using go get

$ go get -u github.com/lovelock/gomemcache/v3/memcache

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

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

Example

For vanilla memcached server

import (
    "github.com/lovelock/gomemcache/v3/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")
        ...
}

For other derivatives

import (
        "github.com/lovelock/gomemcache/v3/memcache"
)

func main() {
    mc := memcache.NewRoundRobin("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
    mc.DisableCAS = true // don't want get casid
    mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})

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

Full docs, see:

See https://godoc.org/github.com/lovelock/gomemcache/v3/memcache

Or run:

$ godoc github.com/lovelock/gomemcache/v3/memcache

Directories

Path Synopsis
Package memcache provides a client for the memcached cache server.
Package memcache provides a client for the memcached cache server.

Jump to

Keyboard shortcuts

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