How to Use Memcached from Go

Connect to Memcached in Go using the gomemcache library to store and retrieve cached data efficiently.

Use the github.com/bradfitz/gomemcache/memcache library to connect to and interact with a Memcached server from Go.

package main

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

func main() {
	client := memcache.New("localhost:11211")
	client.Set(&memcache.Item{Key: "mykey", Value: []byte("my value"), Expiration: 300})
	item, err := client.Get("mykey")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(item.Value))
}