-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (45 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"os"
"golang.org/x/exp/maps"
"github.com/aliexpressru/gomemcached/memcached"
)
func main() {
_ = os.Setenv("MEMCACHED_SERVERS", "localhost:11211")
mcl, err := memcached.InitFromEnv(
memcached.WithMaxIdleConns(10),
memcached.WithAuthentication("admin", "mysecretpassword"),
memcached.WithDisableLogger(),
memcached.WithDisableMemcachedDiagnostic(),
)
mustInit(err)
defer mcl.CloseAllConns()
_, err = mcl.Store(memcached.Set, "foo", 10, []byte("bar"))
mustInit(err)
_, err = mcl.Get("foo")
mustInit(err)
_, err = mcl.Delete("foo")
mustInit(err)
_, err = mcl.Delta(memcached.Increment, "incappend", 1, 1, 0)
mustInit(err)
_, err = mcl.Append(memcached.Append, "incappend", []byte("add"))
mustInit(err)
items := map[string][]byte{
"foo": []byte("bar"),
"gopher": []byte("golang"),
"answer": []byte("42"),
}
err = mcl.MultiStore(memcached.Add, items, 0)
mustInit(err)
_, err = mcl.MultiGet(maps.Keys(items))
mustInit(err)
err = mcl.MultiDelete(maps.Keys(items))
mustInit(err)
err = mcl.FlushAll(0)
mustInit(err)
}
func mustInit(e error) {
if e != nil {
panic(e)
}
}