通用的缓存接口
目前支持以下组件:
名称 | 包 | 状态 |
---|---|---|
memory | 内存 | |
memcached | <github.com/bradfitz/gomemcache> | |
redis | <github.com/redis/go-redis> |
// memory
c, _ := memory.New(...)
c.Set("number", 1)
var v int
c.Get("number",&v)
print(v)
// memcached
c = memcache.New("localhost:11211")
c.Set("number", 1)
c.Get("number", &v)
print(v)
n, setN, exists, err := c.Counter("n")
setN(-1) // 为 n 减 1
setN(10) // 为 n 加上 10
go get github.com/issue9/cache