gocache

package
v1.0.48 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultExpiration = time.Minute * 30 // 默认过期时间
)

Functions

This section is empty.

Types

type Big

type Big struct {
	BigConfig
	// contains filtered or unexported fields
}

Big https://github.com/allegro/bigcache

func NewBig

func NewBig(config *BigConfig) *Big

NewBig 实例化

func (*Big) Get

func (c *Big) Get(key string) (interface{}, error)

Get 获取单个数据

func (*Big) NewCache

func (c *Big) NewCache() *BigCache

NewCache 实例化组件

func (*Big) Set

func (c *Big) Set(key string, value interface{}) error

Set 插入数据 将只显示给定结构的导出字段 序列化并存储

type BigCache

type BigCache struct {
	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

BigCache https://github.com/allegro/bigcache

func (*BigCache) GetInterface

func (gc *BigCache) GetInterface(key string) (ret interface{})

GetInterface 缓存操作

type BigConfig

type BigConfig struct {
	DefaultExpiration time.Duration // 默认过期时间
}

BigConfig 配置

type Etcd

type Etcd struct {
	EtcdConfig                  // 配置
	Client     *clientv3.Client // 驱动
	Kv         clientv3.KV      // kv API子集
	Lease      clientv3.Lease   // lease(租约)对象
	// contains filtered or unexported fields
}

func NewEtcd

func NewEtcd(config *EtcdConfig) (*Etcd, error)

NewEtcd 创建 etcd server

func (Etcd) Del

func (e Etcd) Del(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

Del 删除

func (Etcd) Get

func (e Etcd) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

Get 获取

func (Etcd) Set

func (e Etcd) Set(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

Set 设置

type EtcdConfig

type EtcdConfig struct {
	Endpoints   []string      // 接口 []string{"http://127.0.0.1:2379"}
	DialTimeout time.Duration // time.Second * 5
}

type Go

type Go struct {
	GoConfig
	// contains filtered or unexported fields
}

Go https://github.com/patrickmn/go-cache

func NewGo

func NewGo(config *GoConfig) *Go

NewGo 实例化

func (*Go) Get

func (c *Go) Get(key string) (interface{}, bool)

Get 获取单个数据

func (*Go) NewCache

func (c *Go) NewCache(config *GoCacheConfig) *GoCache

NewCache 实例化

func (*Go) Set

func (c *Go) Set(key string, value interface{}, expirationTime time.Duration)

Set 插入数据 并设置过期时间

func (*Go) SetDefault

func (c *Go) SetDefault(key string, value interface{})

SetDefault 插入数据 并设置为默认过期时间

type GoCache

type GoCache struct {
	GoCacheConfig

	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

GoCache https://github.com/patrickmn/go-cache

func (*GoCache) GetInterface

func (gc *GoCache) GetInterface(key string) (ret interface{})

GetInterface 缓存操作

type GoCacheConfig

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

GoCacheConfig 配置

type GoConfig

type GoConfig struct {
	DefaultExpiration time.Duration // 默认过期时间
	DefaultClear      time.Duration // 清理过期数据
}

GoConfig 配置

type GttInterfaceFunc

type GttInterfaceFunc func() interface{}

GttInterfaceFunc Interface缓存结构

type GttStringFunc

type GttStringFunc func() string

GttStringFunc String缓存结构

type Memcached

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

Memcached https://github.com/bradfitz/gomemcache

func NewMemcached

func NewMemcached(config *MemcachedConfig) *Memcached

NewMemcached 实例化

func (*Memcached) Del

func (m *Memcached) Del(key string) error

Del 删除单个数据

func (*Memcached) Get

func (m *Memcached) Get(key string) (string, error)

Get 获取单个数据

func (*Memcached) NewCache

func (m *Memcached) NewCache() *MemcachedCache

NewCache 实例化

func (*Memcached) Set

func (m *Memcached) Set(key string, value []byte) error

Set 插入数据

type MemcachedCache

type MemcachedCache struct {
	GetterString    GttStringFunc    // 不存在的操作
	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

MemcachedCache https://github.com/bradfitz/gomemcache

func (*MemcachedCache) GetInterface

func (mc *MemcachedCache) GetInterface(key string, result interface{})

GetInterface 缓存操作

func (*MemcachedCache) GetString

func (mc *MemcachedCache) GetString(key string) (ret string)

GetString 缓存操作

type MemcachedConfig

type MemcachedConfig struct {
	Dns string           // 连接地址,可选
	Db  *memcache.Client // 驱动,可选
}

MemcachedConfig 配置

type Redis

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

Redis https://github.com/go-redis/redis

func NewRedis

func NewRedis(config *RedisConfig) *Redis

NewRedis 实例化

func (*Redis) Decr

func (r *Redis) Decr(key string) (int64, error)

Decr 针对一个key的数值进行递减操作

func (*Redis) DecrBy

func (r *Redis) DecrBy(key string, value int64) (int64, error)

DecrBy 针对一个key的数值进行递减操作,指定每次递减多少

func (*Redis) Del

func (r *Redis) Del(keys ...string) error

Del 删除key操作,支持批量删除

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

Get 查询key的值

func (*Redis) GetInterface

func (r *Redis) GetInterface(key string, result interface{}) error

GetInterface 查询key的值

func (*Redis) GetSet

func (r *Redis) GetSet(key string, value interface{}) (string, error)

GetSet 设置一个key的值,并返回这个key的旧值

func (*Redis) Incr

func (r *Redis) Incr(key string) (int64, error)

Incr 针对一个key的数值进行递增操作

func (*Redis) IncrBy

func (r *Redis) IncrBy(key string, value int64) (int64, error)

IncrBy 针对一个key的数值进行递增操作,指定每次递增多少

func (*Redis) MGet

func (r *Redis) MGet(keys ...string) ([]interface{}, error)

MGet 批量查询key的值

func (*Redis) MSet

func (r *Redis) MSet(values map[string]interface{}) error

MSet 批量设置key的值 MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (*Redis) NewCache

func (r *Redis) NewCache(config *RedisCacheConfig) *RedisCache

NewCache 实例化

func (*Redis) NewCacheDefaultExpiration

func (r *Redis) NewCacheDefaultExpiration() *RedisCache

NewCacheDefaultExpiration 实例化

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}, expiration time.Duration) (string, error)

Set 设置一个key的值

func (*Redis) SetDefaultExpiration

func (r *Redis) SetDefaultExpiration(key string, value interface{}) (string, error)

SetDefaultExpiration 设置一个key的值,使用全局默认过期时间

func (*Redis) SetInterface

func (r *Redis) SetInterface(key string, value interface{}, expiration time.Duration) (string, error)

SetInterface 设置一个key的值

func (*Redis) SetInterfaceDefaultExpiration

func (r *Redis) SetInterfaceDefaultExpiration(key string, value interface{}) (string, error)

SetInterfaceDefaultExpiration 设置一个key的值,使用全局默认过期时间

func (*Redis) SetNX

func (r *Redis) SetNX(key string, value interface{}, expiration time.Duration) error

SetNX 如果key不存在,则设置这个key的值

func (*Redis) SetNXDefaultExpiration

func (r *Redis) SetNXDefaultExpiration(key string, value interface{}) error

SetNXDefaultExpiration 如果key不存在,则设置这个key的值,使用全局默认过期时间

type RedisCache

type RedisCache struct {
	RedisCacheConfig

	GetterString    GttStringFunc    // 不存在的操作
	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

RedisCache https://github.com/go-redis/redis

func (*RedisCache) GetInterface

func (rc *RedisCache) GetInterface(key string, result interface{})

GetInterface 缓存操作

func (*RedisCache) GetString

func (rc *RedisCache) GetString(key string) (ret string)

GetString 缓存操作

type RedisCacheConfig

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

RedisCacheConfig 配置

type RedisConfig

type RedisConfig struct {
	Addr              string        // 地址,可选
	Password          string        // 密码,可选
	DbName            int           // 数据库,可选
	DefaultExpiration time.Duration // 默认过期时间
	Db                *redis.Client // 驱动,可选
}

RedisConfig 配置

type Ristretto

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

Ristretto https://github.com/dgraph-io/ristretto

func NewRistretto

func NewRistretto() *Ristretto

NewRistretto 实例化

func (*Ristretto) Del

func (r *Ristretto) Del(key string)

Del 删除数据

func (*Ristretto) Get

func (r *Ristretto) Get(key string) (interface{}, bool)

Get 获取单个数据

func (*Ristretto) NewCache

func (r *Ristretto) NewCache() *RistrettoCache

NewCache 实例化

func (*Ristretto) Set

func (r *Ristretto) Set(key string, value interface{}, cost int64)

Set 插入数据

type RistrettoCache

type RistrettoCache struct {
	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

RistrettoCache https://github.com/dgraph-io/ristretto

func (*RistrettoCache) GetInterface

func (rc *RistrettoCache) GetInterface(key string) (ret interface{})

GetInterface 缓存操作

Jump to

Keyboard shortcuts

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