Documentation
¶
Index ¶
- Constants
- func CheckDataEmpty(data string) bool
- func Get(ctx context.Context, key interface{}) (*vvar.Var, error)
- func GetOrSet(ctx context.Context, key interface{}, value interface{}, ...) (*vvar.Var, error)
- func Set(ctx context.Context, key interface{}, value interface{}, ...) error
- func Update(ctx context.Context, key interface{}, value interface{}) (oldValue *vvar.Var, exist bool, err error)
- type ILocalCache
- type IRedisCache
- type LocalCache
- type RedisCache
- func (r *RedisCache) Del(ctx context.Context, keys ...string) (int64, error)
- func (r *RedisCache) ExpireNX(ctx context.Context, key string, duration time.Duration) (bool, error)
- func (r *RedisCache) Get(ctx context.Context, key string) (string, error)
- func (r *RedisCache) HDel(ctx context.Context, key string, fields ...string) (int64, error)
- func (r *RedisCache) HGet(ctx context.Context, key string, field string) (string, error)
- func (r *RedisCache) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (r *RedisCache) HSet(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *RedisCache) Lock(ctx context.Context, lockName string, duration time.Duration) (res bool, err error)
- func (r *RedisCache) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *RedisCache) SPop(ctx context.Context, key string) (string, error)
- func (r *RedisCache) Set(ctx context.Context, key string, value interface{}, duration time.Duration) (string, error)
- func (r *RedisCache) SetNX(ctx context.Context, key string, value interface{}, duration time.Duration) (bool, error)
- func (r *RedisCache) Unlock(ctx context.Context, lockName string) (int64, error)
- type RedisCacheParam
Constants ¶
const (
DataEmpty = ""
)
Variables ¶
This section is empty.
Functions ¶
func CheckDataEmpty ¶
func Get ¶
Get retrieves and returns the associated value of given `key`. It returns nil if it does not exist, or its value is nil, or it's expired. If you would like to check if the `key` exists in the cache, it's better using function Contains.
func GetOrSet ¶
func GetOrSet(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (*vvar.Var, error)
GetOrSet retrieves and returns the value of `key`, or sets `key`-`value` pair and returns `value` if `key` does not exist in the cache. The key-value pair expires after `duration`.
It does not expire if `duration` == 0. It deletes the `key` if `duration` < 0 or given `value` is nil, but it does nothing if `value` is a function and the function result is nil.
func Set ¶
Set sets cache with `key`-`value` pair, which is expired after `duration`.
It does not expire if `duration` == 0. It deletes the keys of `data` if `duration` < 0 or given `value` is nil.
func Update ¶
func Update(ctx context.Context, key interface{}, value interface{}) (oldValue *vvar.Var, exist bool, err error)
Update updates the value of `key` without changing its expiration and returns the old value. The returned value `exist` is false if the `key` does not exist in the cache.
It deletes the `key` if given `value` is nil. It does nothing if `key` does not exist in the cache.
Types ¶
type ILocalCache ¶
type ILocalCache interface { Get(ctx context.Context, key interface{}) (*vvar.Var, error) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error }
func NewLocalCache ¶
func NewLocalCache() ILocalCache
type IRedisCache ¶
type IRedisCache interface { Del(ctx context.Context, keys ...string) (int64, error) ExpireNX(ctx context.Context, key string, duration time.Duration) (bool, error) Get(ctx context.Context, key string) (string, error) HDel(ctx context.Context, key string, fields ...string) (int64, error) HGet(ctx context.Context, key string, field string) (string, error) HGetAll(ctx context.Context, key string) (map[string]string, error) HSet(ctx context.Context, key string, values ...interface{}) (int64, error) Lock(ctx context.Context, lockName string, duration time.Duration) (res bool, err error) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error) SPop(ctx context.Context, key string) (string, error) Set(ctx context.Context, key string, value interface{}, duration time.Duration) (string, error) SetNX(ctx context.Context, key string, value interface{}, duration time.Duration) (bool, error) Unlock(ctx context.Context, lockName string) (int64, error) }
func NewRedisCache ¶
func NewRedisCache(p RedisCacheParam) IRedisCache