Documentation
¶
Index ¶
- Constants
- Variables
- type BoolValuer
- type Cache
- type Common
- type Hash
- type IntValuer
- type List
- type Memory
- func (mc *Memory) Del(ctx context.Context, keys ...string) IntValuer
- func (mc *Memory) Exists(ctx context.Context, keys ...string) IntValuer
- func (mc *Memory) Expire(ctx context.Context, key string, ttl time.Duration) BoolValuer
- func (mc *Memory) ExpireAt(ctx context.Context, key string, at *time.Time) BoolValuer
- func (mc *Memory) Get(ctx context.Context, key string) StringValuer
- func (mc *Memory) HDel(ctx context.Context, key string, fields ...string) IntValuer
- func (mc *Memory) HGet(ctx context.Context, key string, field string) StringValuer
- func (mc *Memory) HKeys(ctx context.Context, key string) StringSliceValuer
- func (mc *Memory) HLen(ctx context.Context, key string) IntValuer
- func (mc *Memory) HMGet(ctx context.Context, key string, fields ...string) SliceValuer
- func (mc *Memory) HSet(ctx context.Context, key string, data ...any) IntValuer
- func (mc *Memory) HVals(ctx context.Context, key string) StringSliceValuer
- func (mc *Memory) MGet(ctx context.Context, keys ...string) SliceValuer
- func (mc *Memory) Pop(ctx context.Context, key string) StringValuer
- func (mc *Memory) Push(ctx context.Context, key string, data ...any) IntValuer
- func (mc *Memory) Rang(ctx context.Context, key string, start, stop int64) StringSliceValuer
- func (mc *Memory) Set(ctx context.Context, key string, data any, expiration time.Duration) StatusValuer
- func (mc *Memory) SetNX(ctx context.Context, key string, data any, expiration time.Duration) BoolValuer
- func (mc *Memory) Shift(ctx context.Context, key string) StringValuer
- func (mc *Memory) Trim(ctx context.Context, key string, start, stop int64) StatusValuer
- type MemoryDriverStoreType
- type Redis
- func (r *Redis) Del(ctx context.Context, keys ...string) IntValuer
- func (r *Redis) Exists(ctx context.Context, keys ...string) IntValuer
- func (r *Redis) Expire(ctx context.Context, key string, ttl time.Duration) BoolValuer
- func (r *Redis) ExpireAt(ctx context.Context, key string, at *time.Time) BoolValuer
- func (r *Redis) Get(ctx context.Context, key string) StringValuer
- func (r *Redis) HDel(ctx context.Context, key string, fields ...string) IntValuer
- func (r *Redis) HGet(ctx context.Context, key string, field string) StringValuer
- func (r *Redis) HKeys(ctx context.Context, key string) StringSliceValuer
- func (r *Redis) HLen(ctx context.Context, key string) IntValuer
- func (r *Redis) HMGet(ctx context.Context, key string, fields ...string) SliceValuer
- func (r *Redis) HSet(ctx context.Context, key string, data ...any) IntValuer
- func (r *Redis) HVals(ctx context.Context, key string) StringSliceValuer
- func (r *Redis) MGet(ctx context.Context, keys ...string) SliceValuer
- func (r *Redis) Pop(ctx context.Context, key string) StringValuer
- func (r *Redis) Push(ctx context.Context, key string, data ...any) IntValuer
- func (r *Redis) Rang(ctx context.Context, key string, start, stop int64) StringSliceValuer
- func (r *Redis) Set(ctx context.Context, key string, data any, ttl time.Duration) StatusValuer
- func (r *Redis) SetNX(ctx context.Context, key string, data any, ttl time.Duration) BoolValuer
- func (r *Redis) Shift(ctx context.Context, key string) StringValuer
- func (r *Redis) Trim(ctx context.Context, key string, start, stop int64) StatusValuer
- type RedisConfig
- type RedisOptions
- type SliceValuer
- type StatusValuer
- type String
- type StringSliceValuer
- type StringValuer
Constants ¶
View Source
const ValueMaxTTL = time.Hour * 6
ValueMaxTTL 数值最多可存活时长
Variables ¶
View Source
var MemoryNil = errors.New("memory cache: nil")
Functions ¶
This section is empty.
Types ¶
type BoolValuer ¶
BoolValuer 布尔数值接口
type Common ¶
type Common interface {
// Del 删除一个或多个key
Del(ctx context.Context, keys ...string) IntValuer
// Exists 判断某个Key是否存在
Exists(ctx context.Context, keys ...string) IntValuer
// Expire 设置某个key的存活时间
Expire(ctx context.Context, key string, ttl time.Duration) BoolValuer
// ExpireAt 设置某个key在指定时间内到期
ExpireAt(ctx context.Context, key string, at *time.Time) BoolValuer
}
Common 通用接口
type Hash ¶
type Hash interface {
Common
// HDel 哈希表删除指定字段(fields)
HDel(ctx context.Context, key string, fields ...string) IntValuer
// HSet 哈希表设置数据
HSet(ctx context.Context, key string, data ...any) IntValuer
// HGet 哈希表获取一个数据
HGet(ctx context.Context, key string, field string) StringValuer
// HMGet 哈希表获取多个数据
HMGet(ctx context.Context, key string, fields ...string) SliceValuer
// HKeys 哈希表获取某个Key的所有字段(field)
HKeys(ctx context.Context, key string) StringSliceValuer
// HVals 哈希表获取所有值
HVals(ctx context.Context, key string) StringSliceValuer
// HLen 哈希表所有字段的数量
HLen(ctx context.Context, key string) IntValuer
}
Hash 哈希表
func NewRedisHashDriver ¶
func NewRedisHashDriver(opt *RedisOptions) Hash
func NewRedisListDriver ¶
func NewRedisListDriver(opt *RedisOptions) Hash
type List ¶
type List interface {
Common
// Trim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。
//举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。
//下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。
//你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
Trim(ctx context.Context, key string, start, stop int64) StatusValuer
// Push 将数据推入到列表中
Push(ctx context.Context, key string, data ...any) IntValuer
// Rang 提取列表范围内的数据
Rang(ctx context.Context, key string, start, stop int64) StringSliceValuer
// Pop 推出列表尾的最后数据
Pop(ctx context.Context, key string) StringValuer
// Shift 推出列表头的第一个数据
Shift(ctx context.Context, key string) StringValuer
}
List 列表
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) HKeys ¶
func (mc *Memory) HKeys(ctx context.Context, key string) StringSliceValuer
HKeys 哈希表获取某个Key的所有字段(field)
func (*Memory) HVals ¶
func (mc *Memory) HVals(ctx context.Context, key string) StringSliceValuer
HVals 哈希表获取所有值
func (*Memory) MGet ¶
func (mc *Memory) MGet(ctx context.Context, keys ...string) SliceValuer
MGet 获取数据
func (*Memory) Pop ¶
func (mc *Memory) Pop(ctx context.Context, key string) StringValuer
Pop 推出列表尾的最后数据
func (*Memory) Set ¶
func (mc *Memory) Set(ctx context.Context, key string, data any, expiration time.Duration) StatusValuer
Set 设置数据
func (*Memory) SetNX ¶
func (mc *Memory) SetNX(ctx context.Context, key string, data any, expiration time.Duration) BoolValuer
SetNX 设置数据,如果key不存在的话
func (*Memory) Shift ¶
func (mc *Memory) Shift(ctx context.Context, key string) StringValuer
Shift 推出列表头的第一个数据
type MemoryDriverStoreType ¶
type MemoryDriverStoreType string
const ( MemoryDriverStoreTypeString MemoryDriverStoreType = "String" MemoryDriverStoreTypeHash MemoryDriverStoreType = "Hash" MemoryDriverStoreTypeList MemoryDriverStoreType = "List" MemoryDriverStoreTypeSet MemoryDriverStoreType = "Set" MemoryDriverStoreTypeSortedSet MemoryDriverStoreType = "SortedSet" )
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
============================ ========= Redis 实例 =========== ============================
func (*Redis) HKeys ¶
func (r *Redis) HKeys(ctx context.Context, key string) StringSliceValuer
HKeys 哈希表获取某个Key的所有字段(field)
func (*Redis) HVals ¶
func (r *Redis) HVals(ctx context.Context, key string) StringSliceValuer
HVals 哈希表获取所有值
func (*Redis) MGet ¶
func (r *Redis) MGet(ctx context.Context, keys ...string) SliceValuer
MGet 获取多个key的数据
func (*Redis) Pop ¶
func (r *Redis) Pop(ctx context.Context, key string) StringValuer
Pop 推出列表尾的最后数据
func (*Redis) Shift ¶
func (r *Redis) Shift(ctx context.Context, key string) StringValuer
Shift 推出列表头的第一个数据
type RedisConfig ¶
type RedisOptions ¶
type RedisOptions struct {
// contains filtered or unexported fields
}
func (*RedisOptions) Client ¶
func (opt *RedisOptions) Client(cli redis.UniversalClient) *RedisOptions
func (*RedisOptions) Config ¶
func (opt *RedisOptions) Config(cfg *RedisConfig) *RedisOptions
type SliceValuer ¶
type SliceValuer interface {
Val() []any
Err() error
Scan(dst interface{}) error
Result() ([]any, error)
}
SliceValuer 切片数值接口
type StatusValuer ¶
StatusValuer 状态数值接口
type String ¶
type String interface {
Common
// Set 设置数据
Set(ctx context.Context, key string, data any, ttl time.Duration) StatusValuer
// SetNX 如果key不存在才设置数据
SetNX(ctx context.Context, key string, data any, ttl time.Duration) BoolValuer
// Get 获取数据
Get(ctx context.Context, key string) StringValuer
// MGet 获取多个key的数据
MGet(ctx context.Context, keys ...string) SliceValuer
}
String 字符串
func NewMemoryString ¶
func NewMemoryString() String
func NewRedisString ¶
func NewRedisString(opt *RedisOptions) String
type StringSliceValuer ¶
type StringSliceValuer interface {
Val() []string
Err() error
ScanSlice(container interface{}) error
Result() ([]string, error)
}
StringSliceValuer 字符串切片数值接口
type StringValuer ¶
type StringValuer interface {
Val() string
Err() error
Scan(dst any) error
Bytes() ([]byte, error)
Bool() (bool, error)
Int() (int, error)
Int64() (int64, error)
Uint64() (uint64, error)
Float32() (float32, error)
Float64() (float64, error)
Time() (time.Time, error)
Result() (string, error)
}
StringValuer 字符串数值接口
Click to show internal directories.
Click to hide internal directories.