driver

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
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

View Source
var MemoryNil = errors.New("memory cache: nil")

Functions

This section is empty.

Types

type BoolValuer

type BoolValuer interface {
	Val() bool
	Err() error

	Result() (bool, error)
}

BoolValuer 布尔数值接口

type Cache

type Cache interface {
	Common
	String
	Hash
	List
}

Cache 缓存器

func NewMemory

func NewMemory() Cache

func NewRedis

func NewRedis(opt *RedisOptions) Cache

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 IntValuer

type IntValuer interface {
	Val() int64
	Err() error

	Result() (int64, error)
}

IntValuer 整形数值接口

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) Del

func (mc *Memory) Del(ctx context.Context, keys ...string) IntValuer

Del 删除一个或多个key

func (*Memory) Exists

func (mc *Memory) Exists(ctx context.Context, keys ...string) IntValuer

Exists 判断某个Key是否存在

func (*Memory) Expire

func (mc *Memory) Expire(ctx context.Context, key string, ttl time.Duration) BoolValuer

Expire 设置某个key的存活时间

func (*Memory) ExpireAt

func (mc *Memory) ExpireAt(ctx context.Context, key string, at *time.Time) BoolValuer

ExpireAt 设置某个key在指定时间内到期

func (*Memory) Get

func (mc *Memory) Get(ctx context.Context, key string) StringValuer

Get 获取数据

func (*Memory) HDel

func (mc *Memory) HDel(ctx context.Context, key string, fields ...string) IntValuer

HDel 哈希表删除指定字段(fields)

func (*Memory) HExists added in v1.1.6

func (mc *Memory) HExists(ctx context.Context, key, field string) BoolValuer

HExists 检测field是否存在哈希表中

func (*Memory) HGet

func (mc *Memory) HGet(ctx context.Context, key string, field string) StringValuer

HGet 哈希表获取一个数据

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) HLen

func (mc *Memory) HLen(ctx context.Context, key string) IntValuer

HLen 哈希表所有字段的数量

func (*Memory) HMGet

func (mc *Memory) HMGet(ctx context.Context, key string, fields ...string) SliceValuer

HMGet 哈希表获取多个数据

func (*Memory) HSet

func (mc *Memory) HSet(ctx context.Context, key string, data ...interface{}) IntValuer

HSet 哈希表设置数据

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) LLen added in v1.1.6

func (mc *Memory) LLen(ctx context.Context, key string) IntValuer

LLen 获取列表长度

func (*Memory) LPop added in v1.1.6

func (mc *Memory) LPop(ctx context.Context, key string) StringValuer

LPop 推出列表尾的最后数据

func (*Memory) LPush added in v1.1.6

func (mc *Memory) LPush(ctx context.Context, key string, data ...interface{}) IntValuer

LPush 将数据推入到列表中

func (*Memory) LRang added in v1.1.6

func (mc *Memory) LRang(ctx context.Context, key string, start, stop int64) StringSliceValuer

LRang 提取列表范围内的数据

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

func (mc *Memory) LTrim(ctx context.Context, key string, start, stop int64) StatusValuer

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

func (*Memory) Set

func (mc *Memory) Set(ctx context.Context, key string, data interface{}, expiration time.Duration) StatusValuer

Set 设置数据

func (*Memory) SetNX

func (mc *Memory) SetNX(ctx context.Context, key string, data interface{}, expiration time.Duration) BoolValuer

SetNX 设置数据,如果key不存在的话

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) Del

func (r *Redis) Del(ctx context.Context, keys ...string) IntValuer

Del 删除一个或多个key

func (*Redis) Exists

func (r *Redis) Exists(ctx context.Context, keys ...string) IntValuer

Exists 判断某个Key是否存在

func (*Redis) Expire

func (r *Redis) Expire(ctx context.Context, key string, ttl time.Duration) BoolValuer

Expire 设置某个key的存活时间

func (*Redis) ExpireAt

func (r *Redis) ExpireAt(ctx context.Context, key string, at *time.Time) BoolValuer

ExpireAt 设置某个key在指定时间内到期

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string) StringValuer

Get 获取数据

func (*Redis) HDel

func (r *Redis) HDel(ctx context.Context, key string, fields ...string) IntValuer

HDel 哈希表删除指定字段(fields)

func (*Redis) HExists added in v1.1.6

func (r *Redis) HExists(ctx context.Context, key, field string) BoolValuer

HExists 判断哈希表的field是否存在

func (*Redis) HGet

func (r *Redis) HGet(ctx context.Context, key string, field string) StringValuer

HGet 哈希表获取一个数据

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) HLen

func (r *Redis) HLen(ctx context.Context, key string) IntValuer

HLen 哈希表所有字段的数量

func (*Redis) HMGet

func (r *Redis) HMGet(ctx context.Context, key string, fields ...string) SliceValuer

HMGet 哈希表获取多个数据

func (*Redis) HSet

func (r *Redis) HSet(ctx context.Context, key string, data ...interface{}) IntValuer

HSet 哈希表设置数据

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) LLen added in v1.1.6

func (r *Redis) LLen(ctx context.Context, key string) IntValuer

LLen 获取列表的长度

func (*Redis) LPop added in v1.1.6

func (r *Redis) LPop(ctx context.Context, key string) StringValuer

LPop 推出列表尾的最后数据

func (*Redis) LPush added in v1.1.6

func (r *Redis) LPush(ctx context.Context, key string, data ...interface{}) IntValuer

LPush 将数据推入到列表中

func (*Redis) LRang added in v1.1.6

func (r *Redis) LRang(ctx context.Context, key string, start, stop int64) StringSliceValuer

LRang 提取列表范围内的数据

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

func (r *Redis) LTrim(ctx context.Context, key string, start, stop int64) StatusValuer

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,设置成持久性

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, data interface{}, ttl time.Duration) StatusValuer

Set 设置数据

func (*Redis) SetNX

func (r *Redis) SetNX(ctx context.Context, key string, data interface{}, ttl time.Duration) BoolValuer

SetNX 如果key不存在才设置数据

type RedisConfig

type RedisConfig struct {
	// Mode 模式
	// 支持:single,sentinel,cluster
	Mode       string   `yaml:"mode"`
	MasterName string   `yaml:"master_name"`
	Addrs      []string `yaml:"addrs"`
	Database   string   `yaml:"database"`
	Username   string   `yaml:"username"`
	Password   string   `yaml:"password"`
}

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

type StatusValuer interface {
	Val() string
	Err() error

	Result() (string, error)
}

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 字符串数值接口

Jump to

Keyboard shortcuts

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