cache

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) interface{}
	Set(key string, val interface{}, timeout time.Duration) error
	IsExist(key string) bool
	Delete(key string) error

	XRead(key string, count int64) []redis.XStream
	XAdd(key, id string, values []string) (string, error)
	XDel(key string, id string) (int64, error)
}

Cache interface

type Memcache

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

Memcache struct contains *memcache.Client

func NewMemcache

func NewMemcache(server ...string) *Memcache

NewMemcache create new memcache

func (*Memcache) Delete

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

Delete delete value in memcache.

func (*Memcache) Get

func (mem *Memcache) Get(key string) interface{}

Get return cached value

func (*Memcache) IsExist

func (mem *Memcache) IsExist(key string) bool

IsExist check value exists in memcache.

func (*Memcache) Set

func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (err error)

Set cached value with key and expire time.

func (*Memcache) XAdd

func (mem *Memcache) XAdd(key, id string, values []string) (string, error)

XAdd

func (*Memcache) XDel

func (mem *Memcache) XDel(key string, id string) (int64, error)

XDel

func (*Memcache) XRead

func (mem *Memcache) XRead(key string, count int64) []redis.XStream

XRead

type Memory

type Memory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Memory struct contains *memcache.Client

func NewMemory

func NewMemory() *Memory

NewMemory create new memcache

func (*Memory) Delete

func (mem *Memory) Delete(key string) error

Delete delete value in memcache.

func (*Memory) Get

func (mem *Memory) Get(key string) interface{}

Get return cached value

func (*Memory) IsExist

func (mem *Memory) IsExist(key string) bool

IsExist check value exists in memcache.

func (*Memory) Set

func (mem *Memory) Set(key string, val interface{}, timeout time.Duration) (err error)

Set cached value with key and expire time.

type Redis

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

Redis redis cache

func NewRedis

func NewRedis(opts *RedisOpts) *Redis

NewRedis 实例化

func (*Redis) Delete

func (r *Redis) Delete(key string) error

Delete 删除

func (*Redis) Get

func (r *Redis) Get(key string) interface{}

Get 获取一个值

func (*Redis) IsExist

func (r *Redis) IsExist(key string) bool

IsExist 判断key是否存在

func (*Redis) Set

func (r *Redis) Set(key string, val interface{}, timeout time.Duration) (err error)

Set 设置一个值

func (*Redis) XAdd

func (r *Redis) XAdd(key, id string, values []string) (string, error)

XAdd

func (*Redis) XDel

func (r *Redis) XDel(key string, id string) (int64, error)

XDel

func (*Redis) XRead

func (r *Redis) XRead(key string, count int64) []redis.XStream

XRead

type RedisOpts

type RedisOpts struct {
	Host        string `yml:"host" json:"host"`
	Port        int    `yml:"port" json:"port"`
	Password    string `yml:"password" json:"password"`
	Database    int    `yml:"database" json:"database"`
	MaxIdle     int    `yml:"max_idle" json:"max_idle"`
	MaxActive   int    `yml:"max_active" json:"max_active"`
	IdleTimeout int    `yml:"idle_timeout" json:"idle_timeout"` // second
}

RedisOpts redis 连接属性

Jump to

Keyboard shortcuts

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