ubuntu-docker-memcached-golang
v0.0.3
Published
ubuntu docker memcached golang
Downloads
5
Readme
Ubuntu docker memcached
Server
sudo mkdir ~/memcached
cd ~/memcached
sudo rm docker-compose.yml
sudo echo 'version: "3"
services:
memcached:
image: memcached:alpine
ports:
- 1121:11211
container_name: p11211' >> docker-compose.yml && echo docker-compose.yml" created"
sudo echo 'nc -w0 localhost 1121 > /dev/null; [ $? != 0 ] && docker-compose -f /root/memcached/docker-compose.yml up -d &' >> start.sh && echo start.sh" created"
sudo docker-compose up -d
crontab -e
* * * * * root echo $(sh /root/memcached/start.sh)
Client ~/golang/main.go
package main
import (
"fmt"
"github.com/bradfitz/gomemcache/memcache"
)
func main() {
mc := memcache.New("ipv4_server:1121") // ipv4_server: 127.0.0.1
mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
mc.Touch("foo", 20) // set cache expiration time
it, err := mc.Get("foo")
fmt.Println(string(it.Key), string(it.Value), err)
}
Bash command line
ipv4_server=127.0.0.1
telnet $ipv4_server 1121 # ipv4_server: 127.0.0.1
# quit
# stats
# get foo
# ...