package
0.0.0-20190422025920-beccf3fe4313
Repository: https://github.com/changwh/go-common.git
Documentation: pkg.go.dev
# README
go-common/cache/memcache
项目简介
- 提供protobuf,gob,json序列化方式,gzip的memcache接口
编译环境
- 请只用golang v1.7.x以上版本编译执行。
测试
- 执行当前目录下所有测试文件,测试所有功能
特别说明
- 使用protobuf需要在pb文件目录下运行business/make.sh脚本生成go文件才能使用
使用方式
// 初始化
mc := memcache.New(&memcache.Config{})
// 增加 key
err = mc.Set(c, &memcache.Item{})
// 删除key
err := mc.Delete(c,key)
// 获得某个key的内容
err := mc.Get(c,key).Scan(&v)
// 获取多个key的内容
replies, err := mc.GetMulti(c, keys)
for _, key := range replies.Keys() {
if err = rows.Scan(key, &v); err != nil {
return
}
}
# Packages
Package proto is a generated protocol buffer package.
# Functions
Dial connects to the Memcache server at the given network and address using the specified options.
DialConnectTimeout specifies the timeout for connecting to the Memcache server.
DialNetDial specifies a custom dial function for creating TCP connections.
DialReadTimeout specifies the timeout for reading a single command reply.
DialWriteTimeout specifies the timeout for writing a single command.
JSONItem item with FlagJSON flag.
MockWith return a mock conn.
New get a memcache client.
NewConn returns a new memcache connection for the given net connection.
NewPool new a memcache conn pool.
ProtobufItem item with FlagProtobuf flag.
RawItem item with FlagRAW flag.
# Constants
FlagGOB gob encoding.
FlagGzip gzip compress.
FlagJSON json encoding.
FlagProtobuf protobuf.
FlagRAW default flag.
# Variables
ErrCASConflict means that a CompareAndSwap call failed due to the cached value being modified between the Get and the CompareAndSwap.
ErrConnClosed conn closed.
ErrExists exists.
ErrItem item nil.
ErrItemObject object type Assertion failed.
ErrMalformedKey is returned when an invalid key is used.
ErrNotFound not found.
ErrNotStored not stored.
ErrPoolClosed pool closed.
ErrPoolExhausted is returned from a pool connection method (Store, Get, Delete, IncrDecr, Err) when the maximum number of database connections in the pool has been reached.
ErrStat stat error for monitor.
ErrValueSize item value size must less than 1mb.
# Structs
Config memcache config.
DialOption specifies an option for dialing a Memcache server.
Item is an reply to be got or stored in a memcached server.
Memcache memcache client.
MockErr for unit test.
Pool memcache connection pool struct.
Replies is the result of GetMulti.
Reply is the result of Get.
# Interfaces
Conn represents a connection to a Memcache server.
# Type aliases
Error represents an error returned in a command reply.