Documentation ¶
Index ¶
- Constants
- Variables
- func RandomExpirationDuration() time.Duration
- type Client
- func (cli *Client) Del(ctx context.Context, keys ...string) error
- func (cli *Client) Exists(ctx context.Context, keys ...string) (int64, error)
- func (cli *Client) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (cli *Client) ExpireAt(ctx context.Context, key string, at time.Time) error
- type HashClient
- func (cli *HashClient) Del(ctx context.Context, keys ...string) error
- func (cli *HashClient) Exists(ctx context.Context, keys ...string) (int64, error)
- func (cli *HashClient) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (cli *HashClient) ExpireAt(ctx context.Context, key string, at time.Time) error
- func (cli *HashClient) HDel(ctx context.Context, key string, fields ...string) error
- func (cli *HashClient) HExists(ctx context.Context, key, field string) (bool, error)
- func (cli *HashClient) HGet(ctx context.Context, key, field string) (string, error)
- func (cli *HashClient) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (cli *HashClient) HGetAndScan(ctx context.Context, dst interface{}, key, field string) error
- func (cli *HashClient) HKeys(ctx context.Context, key string) ([]string, error)
- func (cli *HashClient) HKeysAndScan(ctx context.Context, dst interface{}, key string) error
- func (cli *HashClient) HLen(ctx context.Context, key string) (int64, error)
- func (cli *HashClient) HMGet(ctx context.Context, key string, fields ...string) ([]interface{}, error)
- func (cli *HashClient) HMGetAndScan(ctx context.Context, dst interface{}, key string, fields ...string) error
- func (cli *HashClient) HSet(ctx context.Context, key string, values ...interface{}) error
- func (cli *HashClient) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
- func (cli *HashClient) HVals(ctx context.Context, key string) ([]string, error)
- func (cli *HashClient) HValsAndScan(ctx context.Context, dst interface{}, key string) error
- type ListClient
- func (cli *ListClient) Del(ctx context.Context, keys ...string) error
- func (cli *ListClient) Exists(ctx context.Context, keys ...string) (int64, error)
- func (cli *ListClient) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (cli *ListClient) ExpireAt(ctx context.Context, key string, at time.Time) error
- func (cli *ListClient) LLen(ctx context.Context, key string) (int64, error)
- func (cli *ListClient) LPop(ctx context.Context, key string) (string, error)
- func (cli *ListClient) LPopAndScan(ctx context.Context, dst interface{}, key string) error
- func (cli *ListClient) LPush(ctx context.Context, key string, data ...interface{}) error
- func (cli *ListClient) LRang(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (cli *ListClient) LRangAndScan(ctx context.Context, dst interface{}, key string, start, stop int64) error
- func (cli *ListClient) LShift(ctx context.Context, key string) (string, error)
- func (cli *ListClient) LShiftAndScan(ctx context.Context, dst interface{}, key string) error
- func (cli *ListClient) LTrim(ctx context.Context, key string, start, stop int64) error
- type StringClient
- func (cli *StringClient) CheckAndGet(ctx context.Context, key string) (string, error)
- func (cli *StringClient) CheckAndScan(ctx context.Context, dst interface{}, key string) error
- func (cli *StringClient) Del(ctx context.Context, keys ...string) error
- func (cli *StringClient) Exists(ctx context.Context, keys ...string) (int64, error)
- func (cli *StringClient) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (cli *StringClient) ExpireAt(ctx context.Context, key string, at time.Time) error
- func (cli *StringClient) Get(ctx context.Context, key string) (string, error)
- func (cli *StringClient) GetAndScan(ctx context.Context, dst interface{}, key string) error
- func (cli *StringClient) MGet(ctx context.Context, keys ...string) ([]interface{}, error)
- func (cli *StringClient) MGetAndScan(ctx context.Context, dst interface{}, keys ...string) error
- func (cli *StringClient) Set(ctx context.Context, key string, data interface{}, expiration time.Duration) error
- func (cli *StringClient) SetNX(ctx context.Context, key string, data interface{}, expiration time.Duration) error
Constants ¶
const ( // KeepTTL 保持原先的过期时间(TTL) KeepTTL = -1 // DefaultEmptySetNXDuration 默认空对象设置过期时效 DefaultEmptySetNXDuration = time.Second * 10 // DefaultExpirationDuration 默认缓存过期时效 DefaultExpirationDuration = time.Hour )
Variables ¶
var ( ErrEmpty = errors.New("empty") ErrNoCacheClient = errors.New("no cache client init") ErrNoRecord = errors.New("no record") )
Functions ¶
func RandomExpirationDuration ¶
RandomExpirationDuration 以 DefaultExpirationDuration 为基础,返回一个 DefaultExpirationDuration ± 30m 内的时间长度
Types ¶
type Client ¶
type Client struct { StringClient HashClient ListClient // contains filtered or unexported fields }
type HashClient ¶
type HashClient struct {
// contains filtered or unexported fields
}
func NewHashClient ¶
func NewHashClient(drivers ...driver.Hash) *HashClient
func (*HashClient) HGetAndScan ¶
func (cli *HashClient) HGetAndScan(ctx context.Context, dst interface{}, key, field string) error
HGetAndScan 获取Hash表指定字段的值
func (*HashClient) HKeysAndScan ¶
func (cli *HashClient) HKeysAndScan(ctx context.Context, dst interface{}, key string) error
HKeysAndScan 获取Hash表的所有键并扫描到dst中
func (*HashClient) HMGet ¶
func (cli *HashClient) HMGet(ctx context.Context, key string, fields ...string) ([]interface{}, error)
HMGet 获取Hash表指定字段的值
func (*HashClient) HMGetAndScan ¶
func (cli *HashClient) HMGetAndScan(ctx context.Context, dst interface{}, key string, fields ...string) error
HMGetAndScan 获取Hash表指定字段的值并扫描进入到dst中
func (*HashClient) HSet ¶
func (cli *HashClient) HSet(ctx context.Context, key string, values ...interface{}) error
HSet 写入hash数据 接受以下格式的值: HSet("myhash", "key1", "value1", "key2", "value2")
HSet("myhash", []string{"key1", "value1", "key2", "value2"})
HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"}) 使用“redis”标签播放结构。 type MyHash struct { Key1 string `redis:"key1"`; Key2 int `redis:"key2"` }
HSet("myhash", MyHash{"value1", "value2"}) 警告:redis-server >= 4.0 对于struct,可以是结构体指针类型,我们只解析标签为redis的字段。如果你不想读取该字段,可以使用 `redis:"-"` 标志来忽略它,或者不需要设置 redis 标签。对于结构体字段的类型,我们只支持简单的数据类型:string、int/uint(8,16,32,64)、float(32,64)、time.Time(to RFC3339Nano)、time.Duration(to Nanoseconds) ),如果是其他更复杂或者自定义的数据类型,请实现encoding.BinaryMarshaler接口。
func (*HashClient) HSetNX ¶
func (cli *HashClient) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
HSetNX 哈希表设置某个字段的值,如果存在的话返回true
func (*HashClient) HValsAndScan ¶
func (cli *HashClient) HValsAndScan(ctx context.Context, dst interface{}, key string) error
HValsAndScan 获取Hash表的所有值并扫如dst中
type ListClient ¶
type ListClient struct {
// contains filtered or unexported fields
}
func NewListClient ¶
func NewListClient(drivers ...driver.List) *ListClient
func (*ListClient) LPopAndScan ¶
func (cli *ListClient) LPopAndScan(ctx context.Context, dst interface{}, key string) error
LPopAndScan 通过扫描方式移除并取出列表内的最后一个元素
func (*ListClient) LPush ¶
func (cli *ListClient) LPush(ctx context.Context, key string, data ...interface{}) error
LPush 推送数据
func (*ListClient) LRangAndScan ¶
func (cli *ListClient) LRangAndScan(ctx context.Context, dst interface{}, key string, start, stop int64) error
LRangAndScan 通过扫描方式获取列表内的范围内数据
func (*ListClient) LShiftAndScan ¶
func (cli *ListClient) LShiftAndScan(ctx context.Context, dst interface{}, key string) error
LShiftAndScan 通过扫描方式移除并取出列表内的第一个元素
type StringClient ¶
type StringClient struct {
// contains filtered or unexported fields
}
func NewStringClient ¶
func NewStringClient(drivers ...driver.String) *StringClient
func (*StringClient) CheckAndGet ¶
CheckAndGet 检测并获取数据
func (*StringClient) CheckAndScan ¶
func (cli *StringClient) CheckAndScan(ctx context.Context, dst interface{}, key string) error
CheckAndScan 获取数据
func (*StringClient) GetAndScan ¶
func (cli *StringClient) GetAndScan(ctx context.Context, dst interface{}, key string) error
GetAndScan 获取并扫描
func (*StringClient) MGet ¶
func (cli *StringClient) MGet(ctx context.Context, keys ...string) ([]interface{}, error)
MGet 获取多个Keys的值
func (*StringClient) MGetAndScan ¶
func (cli *StringClient) MGetAndScan(ctx context.Context, dst interface{}, keys ...string) error
MGetAndScan 获取多个Keys的值并扫描进dst中