Documentation ¶
Index ¶
- Constants
- Variables
- type BoolValuer
- type Cache
- type Common
- type Hash
- type IntValuer
- type List
- type MapStringStringValuer
- 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) HExists(ctx context.Context, key, field string) BoolValuer
- func (mc *Memory) HGet(ctx context.Context, key string, field string) StringValuer
- func (mc *Memory) HGetAll(ctx context.Context, key string) MapStringStringValuer
- 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 ...interface{}) IntValuer
- func (mc *Memory) HSetNX(ctx context.Context, key, field string, data interface{}) BoolValuer
- func (mc *Memory) HVals(ctx context.Context, key string) StringSliceValuer
- func (mc *Memory) LLen(ctx context.Context, key string) IntValuer
- func (mc *Memory) LPop(ctx context.Context, key string) StringValuer
- func (mc *Memory) LPush(ctx context.Context, key string, data ...interface{}) IntValuer
- func (mc *Memory) LRang(ctx context.Context, key string, start, stop int64) StringSliceValuer
- func (mc *Memory) LShift(ctx context.Context, key string) StringValuer
- func (mc *Memory) LTrim(ctx context.Context, key string, start, stop int64) StatusValuer
- func (mc *Memory) MGet(ctx context.Context, keys ...string) SliceValuer
- func (mc *Memory) Persist(ctx context.Context, key string) BoolValuer
- func (mc *Memory) Set(ctx context.Context, key string, data interface{}, expiration time.Duration) StatusValuer
- func (mc *Memory) SetNX(ctx context.Context, key string, data interface{}, expiration time.Duration) BoolValuer
- 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) HExists(ctx context.Context, key, field string) BoolValuer
- func (r *Redis) HGet(ctx context.Context, key string, field string) StringValuer
- func (r *Redis) HGetAll(ctx context.Context, key string) MapStringStringValuer
- 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 ...interface{}) IntValuer
- func (r *Redis) HSetNX(ctx context.Context, key, field string, data interface{}) BoolValuer
- func (r *Redis) HVals(ctx context.Context, key string) StringSliceValuer
- func (r *Redis) LLen(ctx context.Context, key string) IntValuer
- func (r *Redis) LPop(ctx context.Context, key string) StringValuer
- func (r *Redis) LPush(ctx context.Context, key string, data ...interface{}) IntValuer
- func (r *Redis) LRang(ctx context.Context, key string, start, stop int64) StringSliceValuer
- func (r *Redis) LShift(ctx context.Context, key string) StringValuer
- func (r *Redis) LTrim(ctx context.Context, key string, start, stop int64) StatusValuer
- func (r *Redis) MGet(ctx context.Context, keys ...string) SliceValuer
- func (r *Redis) Persist(ctx context.Context, key string) BoolValuer
- func (r *Redis) Set(ctx context.Context, key string, data interface{}, ttl time.Duration) StatusValuer
- func (r *Redis) SetNX(ctx context.Context, key string, data interface{}, ttl time.Duration) BoolValuer
- type RedisConfig
- type RedisOptions
- type SliceValuer
- type StatusValuer
- type String
- type StringSliceValuer
- type StringValuer
Constants ¶
const ( // KeepTTL 保持原有的存活时间 KeepTTL time.Duration = -1 // ValueMaxTTL 数值最多可存活时长 ValueMaxTTL = time.Hour * 6 )
*
@author : Jerbe - The porter from Earth @time : 2023/9/13 15:09 @describe :
Variables ¶
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 // Persist 将某个Key设置成持久性 Persist(ctx context.Context, key string) BoolValuer }
Common 通用接口
type Hash ¶
type Hash interface { Common // HExists 判断field是否存在 HExists(ctx context.Context, key, field string) BoolValuer // HDel 哈希表删除指定字段(fields) HDel(ctx context.Context, key string, fields ...string) IntValuer // HSet 哈希表设置数据 HSet(ctx context.Context, key string, data ...interface{}) IntValuer // HSetNX 设置哈希表field对应的值,当field不存在时才能成功 HSetNX(ctx context.Context, key, field string, data interface{}) BoolValuer // 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 // HGetAll 获取哈希表的键跟值 HGetAll(ctx context.Context, key string) MapStringStringValuer // 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 // LTrim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 //举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 //下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 //你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 LTrim(ctx context.Context, key string, start, stop int64) StatusValuer // LPush 将数据推入到列表中 LPush(ctx context.Context, key string, data ...interface{}) IntValuer // LRang 提取列表范围内的数据 LRang(ctx context.Context, key string, start, stop int64) StringSliceValuer // LPop 推出列表尾的最后数据 LPop(ctx context.Context, key string) StringValuer // LShift 推出列表头的第一个数据 LShift(ctx context.Context, key string) StringValuer // LLen 获取list列表的长度 LLen(ctx context.Context, key string) IntValuer }
List 列表
type MapStringStringValuer ¶ added in v1.1.6
type MapStringStringValuer interface { Val() map[string]string Err() error Scan(dst interface{}) error Result() (map[string]string, error) }
MapStringStringValuer 以string为键string为值的map
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) HExists ¶ added in v1.1.6
func (mc *Memory) HExists(ctx context.Context, key, field string) BoolValuer
HExists 检测field是否存在哈希表中
func (*Memory) HGetAll ¶ added in v1.1.6
func (mc *Memory) HGetAll(ctx context.Context, key string) MapStringStringValuer
HGetAll 获取哈希表所有的数据,包括field跟value
func (*Memory) HKeys ¶
func (mc *Memory) HKeys(ctx context.Context, key string) StringSliceValuer
HKeys 哈希表获取某个Key的所有字段(field)
func (*Memory) HSetNX ¶ added in v1.1.6
func (mc *Memory) HSetNX(ctx context.Context, key, field string, data interface{}) BoolValuer
HSetNX 如果哈希表的field不存在,则设置成功
func (*Memory) HVals ¶
func (mc *Memory) HVals(ctx context.Context, key string) StringSliceValuer
HVals 哈希表获取所有值
func (*Memory) LPop ¶ added in v1.1.6
func (mc *Memory) LPop(ctx context.Context, key string) StringValuer
LPop 推出列表尾的最后数据
func (*Memory) LShift ¶ added in v1.1.6
func (mc *Memory) LShift(ctx context.Context, key string) StringValuer
LShift 推出列表头的第一个数据
func (*Memory) LTrim ¶ added in v1.1.6
LTrim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
func (*Memory) MGet ¶
func (mc *Memory) MGet(ctx context.Context, keys ...string) SliceValuer
MGet 获取数据
func (*Memory) Persist ¶ added in v1.1.6
func (mc *Memory) Persist(ctx context.Context, key string) BoolValuer
Persist 删除key的过期时间,并设置成持久性 注意,持久化后最长也也不会超过 ValueMaxTTL
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) HExists ¶ added in v1.1.6
func (r *Redis) HExists(ctx context.Context, key, field string) BoolValuer
HExists 判断哈希表的field是否存在
func (*Redis) HGetAll ¶ added in v1.1.6
func (r *Redis) HGetAll(ctx context.Context, key string) MapStringStringValuer
HGetAll 哈希表获取所有值,包括field跟value
func (*Redis) HKeys ¶
func (r *Redis) HKeys(ctx context.Context, key string) StringSliceValuer
HKeys 哈希表获取某个Key的所有字段(field)
func (*Redis) HSetNX ¶ added in v1.1.6
func (r *Redis) HSetNX(ctx context.Context, key, field string, data interface{}) BoolValuer
HSetNX 设置哈希表field对应的值,当field不存在时才能成功
func (*Redis) HVals ¶
func (r *Redis) HVals(ctx context.Context, key string) StringSliceValuer
HVals 哈希表获取所有值
func (*Redis) LPop ¶ added in v1.1.6
func (r *Redis) LPop(ctx context.Context, key string) StringValuer
LPop 推出列表尾的最后数据
func (*Redis) LShift ¶ added in v1.1.6
func (r *Redis) LShift(ctx context.Context, key string) StringValuer
LShift 推出列表头的第一个数据
func (*Redis) LTrim ¶ added in v1.1.6
LTrim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
func (*Redis) MGet ¶
func (r *Redis) MGet(ctx context.Context, keys ...string) SliceValuer
MGet 获取多个key的数据
func (*Redis) Persist ¶ added in v1.1.6
func (r *Redis) Persist(ctx context.Context, key string) BoolValuer
Persist 移除某个key的TTL,设置成持久性
type RedisConfig ¶
type RedisOptions ¶
type RedisOptions struct { Config *RedisConfig Client redis.UniversalClient }
func NewRedisOptionsWithClient ¶ added in v1.1.4
func NewRedisOptionsWithClient(cli redis.UniversalClient) *RedisOptions
func NewRedisOptionsWithConfig ¶ added in v1.1.4
func NewRedisOptionsWithConfig(cfg *RedisConfig) *RedisOptions
type SliceValuer ¶
type SliceValuer interface { Val() []interface{} Err() error Scan(dst interface{}) error Result() ([]interface{}, error) }
SliceValuer 切片数值接口
type StatusValuer ¶
StatusValuer 状态数值接口
type String ¶
type String interface { Common // Set 设置数据 Set(ctx context.Context, key string, data interface{}, ttl time.Duration) StatusValuer // SetNX 如果key不存在才设置数据 SetNX(ctx context.Context, key string, data interface{}, 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 interface{}) 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 字符串数值接口