driver

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Index

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

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
}

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 IntValuer

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

	Result() (int64, error)
}

IntValuer 整形数值接口

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

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

HGet 哈希表获取一个数据

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 ...any) IntValuer

HSet 哈希表设置数据

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

func (mc *Memory) Push(ctx context.Context, key string, data ...any) IntValuer

Push 将数据推入到列表中

func (*Memory) Rang

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

Rang 提取列表范围内的数据

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 推出列表头的第一个数据

func (*Memory) Trim

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

Trim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。

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

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

HGet 哈希表获取一个数据

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 ...any) IntValuer

HSet 哈希表设置数据

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

func (r *Redis) Push(ctx context.Context, key string, data ...any) IntValuer

Push 将数据推入到列表中

func (*Redis) Rang

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

Rang 提取列表范围内的数据

func (*Redis) Set

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

Set 设置数据

func (*Redis) SetNX

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

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

func (*Redis) Shift

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

Shift 推出列表头的第一个数据

func (*Redis) Trim

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

Trim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。

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 {
	// 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

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

Jump to

Keyboard shortcuts

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