memcache

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMemcacheNotExists = errors.New("指定Memcache不存在,或未初始化")
)

Functions

func Init added in v0.1.6

func Init(conf []Config) error

Init 初始化数据库

Types

type Config added in v0.2.23

type Config struct {
	Name   string         `json:"name" toml:"name"`
	Server []ServerConfig `json:"server" toml:"server"`
}

type Manager

type Manager struct {
	sync.Map
}

type Memcache

type Memcache struct {
	// contains filtered or unexported fields
}

func Client added in v0.2.23

func Client(name string) (*Memcache, error)

Client 通过名称获取Memcache

func (*Memcache) Add

func (m *Memcache) Add(key string, value []byte, expiration int32) error

Add 如果给定项的键值不存在,则写入该项。如果不满足该条件,则返回ErrNotStored

func (*Memcache) Conn

func (m *Memcache) Conn() *memcache.Client

Conn 获取memcache

func (*Memcache) Decrement

func (m *Memcache) Decrement(key string, delta uint64) (uint64, error)

Decrement 按增量原子递减键的值 返回值是递减或出错后的新值 如果该值在memcache中不存在,则错误为ErrCacheMiss memcache中的值必须是十进制数,否则将返回错误

func (*Memcache) Delete

func (m *Memcache) Delete(key string) error

Delete 使用提供的键删除项。如果缓存中不存在该项,则返回错误ErrCacheMiss。

func (*Memcache) Get

func (m *Memcache) Get(key string) ([]byte, error)

Get 获取给定key的项,key的长度必须不超过250字节。

func (*Memcache) GetMulti

func (m *Memcache) GetMulti(keys []string) (map[string][]byte, error)

GetMulti GetMulti是Get的批处理版本

func (*Memcache) Increment

func (m *Memcache) Increment(key string, delta uint64) (uint64, error)

Increment 按增量键原子递增 返回值是递增或出错后的新值 如果该值在memcache中不存在,则错误为ErrCacheMiss memcache中的值必须是十进制数,否则将返回错误

func (*Memcache) Replace

func (m *Memcache) Replace(key string, value []byte, expiration int32) error

Replace 写入给定项,但仅当服务器*确实*已经保存此键的数据

func (*Memcache) Set

func (m *Memcache) Set(key string, value []byte, expiration int32) error

Set 无条件地写入给定项

func (*Memcache) Touch

func (m *Memcache) Touch(key string, seconds int32) error

Touch 更新给定密钥的有效期 seconds参数是Unix时间戳,如果秒数小于1个月,则是该项将在未来过期的秒数。 0表示该项目没有过期时间 如果键不在缓存中,则返回ErrCacheMiss key的长度必须不超过250字节

type ServerConfig added in v0.2.23

type ServerConfig struct {
	Host string `json:"host" toml:"host"`
	Port int    `json:"port" toml:"port"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL