services

package
v0.0.0-...-8d54ad1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoneDuration = time.Duration(-1)
)

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var ErrTypeNotOk = errors.New("val type not ok")

Functions

func NewMemoryCache

func NewMemoryCache(params ...interface{}) (interface{}, error)

func NewRedisCache

func NewRedisCache(params ...interface{}) (interface{}, error)

NewRedisCache 初始化redis服务

Types

type MemoryCache

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

func (*MemoryCache) Calc

func (m *MemoryCache) Calc(ctx context.Context, key string, step int64) (int64, error)

func (*MemoryCache) Decrement

func (m *MemoryCache) Decrement(ctx context.Context, key string) (int64, error)

func (*MemoryCache) Del

func (m *MemoryCache) Del(ctx context.Context, key string) error

func (*MemoryCache) DelMany

func (m *MemoryCache) DelMany(ctx context.Context, keys []string) error

func (*MemoryCache) Get

func (m *MemoryCache) Get(ctx context.Context, key string) (string, error)

func (*MemoryCache) GetMany

func (m *MemoryCache) GetMany(ctx context.Context, keys []string) (map[string]string, error)

func (*MemoryCache) GetObj

func (m *MemoryCache) GetObj(ctx context.Context, key string, obj interface{}) error

func (*MemoryCache) GetTTL

func (m *MemoryCache) GetTTL(ctx context.Context, key string) (time.Duration, error)

func (*MemoryCache) Increment

func (m *MemoryCache) Increment(ctx context.Context, key string) (int64, error)

func (*MemoryCache) Remember

func (m *MemoryCache) Remember(ctx context.Context, key string, timeout time.Duration, rememberFunc contract.RememberFunc, obj interface{}) error

func (*MemoryCache) Set

func (m *MemoryCache) Set(ctx context.Context, key string, val string, timeout time.Duration) error

func (*MemoryCache) SetForever

func (m *MemoryCache) SetForever(ctx context.Context, key string, val string) error

func (*MemoryCache) SetForeverObj

func (m *MemoryCache) SetForeverObj(ctx context.Context, key string, val interface{}) error

func (*MemoryCache) SetMany

func (m *MemoryCache) SetMany(ctx context.Context, data map[string]string, timeout time.Duration) error

func (*MemoryCache) SetObj

func (m *MemoryCache) SetObj(ctx context.Context, key string, val interface{}, timeout time.Duration) error

func (*MemoryCache) SetTTL

func (m *MemoryCache) SetTTL(ctx context.Context, key string, timeout time.Duration) error

type MemoryData

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

type RedisCache

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

RedisCache 代表Redis缓存

func (*RedisCache) Calc

func (r *RedisCache) Calc(ctx context.Context, key string, step int64) (int64, error)

func (*RedisCache) Decrement

func (r *RedisCache) Decrement(ctx context.Context, key string) (int64, error)

func (*RedisCache) Del

func (r *RedisCache) Del(ctx context.Context, key string) error

func (*RedisCache) DelMany

func (r *RedisCache) DelMany(ctx context.Context, keys []string) error

func (*RedisCache) Get

func (r *RedisCache) Get(ctx context.Context, key string) (string, error)

Get 获取某个key对应的字符串

func (*RedisCache) GetMany

func (r *RedisCache) GetMany(ctx context.Context, keys []string) (map[string]string, error)

GetMany 获取某些key对应的值

func (*RedisCache) GetObj

func (r *RedisCache) GetObj(ctx context.Context, key string, model interface{}) error

GetObj 获取某个key对应的对象, 对象必须实现 https://pkg.go.dev/encoding#BinaryUnMarshaler

func (*RedisCache) GetTTL

func (r *RedisCache) GetTTL(ctx context.Context, key string) (time.Duration, error)

GetTTL 获取某个key的超时时间

func (*RedisCache) Increment

func (r *RedisCache) Increment(ctx context.Context, key string) (int64, error)

func (*RedisCache) Remember

func (r *RedisCache) Remember(ctx context.Context, key string, timeout time.Duration, rememberFunc contract.RememberFunc, obj interface{}) error

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, val string, timeout time.Duration) error

Set 设置某个key和值到缓存,带超时时间

func (*RedisCache) SetForever

func (r *RedisCache) SetForever(ctx context.Context, key string, val string) error

SetForever 设置某个key和值到缓存,不带超时时间

func (*RedisCache) SetForeverObj

func (r *RedisCache) SetForeverObj(ctx context.Context, key string, val interface{}) error

SetForeverObj 设置某个key和对象到缓存,不带超时时间,对象必须实现 https://pkg.go.dev/encoding#BinaryMarshaler

func (*RedisCache) SetMany

func (r *RedisCache) SetMany(ctx context.Context, data map[string]string, timeout time.Duration) error

SetMany 设置多个key和值到缓存

func (*RedisCache) SetObj

func (r *RedisCache) SetObj(ctx context.Context, key string, val interface{}, timeout time.Duration) error

SetObj 设置某个key和对象到缓存, 对象必须实现 https://pkg.go.dev/encoding#BinaryMarshaler

func (*RedisCache) SetTTL

func (r *RedisCache) SetTTL(ctx context.Context, key string, timeout time.Duration) error

SetTTL 设置某个key的超时时间

Jump to

Keyboard shortcuts

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