ESSAY / NOTE

golang操作memcached

项目地址 https://github.com/bradfitz/gomemcache
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")
     fmt.Println(string(it.Value))
}
golang []byte和string相互转换
 
func main() {
    str2 := "hello"
    data2 := []byte(str2)
    fmt.Println(data2)
    str2 = string(data2)
    fmt.Println(str2)
}
string 转为[]byte
var str string = "test"
var data []byte = []byte(str)