redis

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MemoryUsage

func MemoryUsage(ctx context.Context, client redis.Cmdable, key string) (size int64, err error)

func ValueType

func ValueType(ctx context.Context, client redis.Cmdable, key string) (ValueType string, err error)

Types

type Arg

type Arg interface {
	IsArg()
}

type ArgCache

type ArgCache struct {
	Param    *Param
	SizeArg  *SizeArg
	CountArg *CountArg
	StartArg *StartArg
}

type ClusterService

type ClusterService struct {
	*Config

	*CmdService
	// contains filtered or unexported fields
}

func (*ClusterService) Close

func (this_ *ClusterService) Close()

func (*ClusterService) DelPattern

func (this_ *ClusterService) DelPattern(pattern string, args ...Arg) (count int, err error)

func (*ClusterService) GetClient

func (this_ *ClusterService) GetClient(args ...Arg) (client redis.Cmdable, err error)

func (*ClusterService) GetValueInfo

func (this_ *ClusterService) GetValueInfo(key string, args ...Arg) (valueInfo *ValueInfo, err error)

func (*ClusterService) Keys

func (this_ *ClusterService) Keys(pattern string, args ...Arg) (keysResult *KeysResult, err error)

func (*ClusterService) Scan

func (this_ *ClusterService) Scan(pattern string, args ...Arg) (keysResult *KeysResult, err error)

func (*ClusterService) ValueType

func (this_ *ClusterService) ValueType(key string, args ...Arg) (valueType string, err error)

type CmdService

type CmdService struct {
	ThrowNotFoundErr bool
	GetClient        func(param *Param) (client redis.Cmdable, err error) `json:"-"`
}

func (*CmdService) BitCount

func (this_ *CmdService) BitCount(key string, args ...Arg) (count int64, err error)

func (*CmdService) BitSet

func (this_ *CmdService) BitSet(key string, offset int64, value int, args ...Arg) (err error)

func (*CmdService) Del

func (this_ *CmdService) Del(key string, args ...Arg) (count int, err error)

func (*CmdService) Exists

func (this_ *CmdService) Exists(key string, args ...Arg) (res int64, err error)

Exists key是否存在

func (*CmdService) Expire

func (this_ *CmdService) Expire(key string, expire int64, args ...Arg) (res bool, err error)

Expire 让给定键在指定的秒数之后过期

func (*CmdService) Get

func (this_ *CmdService) Get(key string, args ...Arg) (value string, err error)

func (*CmdService) HashDel

func (this_ *CmdService) HashDel(key string, field string, args ...Arg) (err error)

func (*CmdService) HashGet

func (this_ *CmdService) HashGet(key string, field string, args ...Arg) (value string, err error)

func (*CmdService) HashGetAll

func (this_ *CmdService) HashGetAll(key string, args ...Arg) (value map[string]string, err error)

func (*CmdService) HashSet

func (this_ *CmdService) HashSet(key string, field string, value string, args ...Arg) (err error)

func (*CmdService) Incr

func (this_ *CmdService) Incr(key string, value int64, args ...Arg) (res int64, err error)

func (*CmdService) Info

func (this_ *CmdService) Info(args ...Arg) (res string, err error)

func (*CmdService) IsNotFound

func (this_ *CmdService) IsNotFound(err error) (res bool)

func (*CmdService) ListPush

func (this_ *CmdService) ListPush(key string, value string, args ...Arg) (err error)

func (*CmdService) ListRPush

func (this_ *CmdService) ListRPush(key string, value string, args ...Arg) (err error)

func (*CmdService) ListRem

func (this_ *CmdService) ListRem(key string, count int64, value string, args ...Arg) (err error)

func (*CmdService) ListSet

func (this_ *CmdService) ListSet(key string, index int64, value string, args ...Arg) (err error)

func (*CmdService) Persist

func (this_ *CmdService) Persist(key string, args ...Arg) (res bool, err error)

Persist 移除键的过期时间

func (*CmdService) ScriptRun

func (this_ *CmdService) ScriptRun(src string, KEYS []string, ARGV interface{}, args ...Arg) (value interface{}, err error)

func (*CmdService) Set

func (this_ *CmdService) Set(key string, value string, args ...Arg) (err error)

func (*CmdService) SetAdd

func (this_ *CmdService) SetAdd(key string, value string, args ...Arg) (err error)

func (*CmdService) SetCard

func (this_ *CmdService) SetCard(key string, args ...Arg) (res int64, err error)

func (*CmdService) SetRem

func (this_ *CmdService) SetRem(key string, value string, args ...Arg) (err error)

func (*CmdService) SetThrowNotFoundErr

func (this_ *CmdService) SetThrowNotFoundErr(ThrowNotFoundErr bool)

func (*CmdService) Ttl

func (this_ *CmdService) Ttl(key string, args ...Arg) (res int64, err error)

Ttl 查看给定键距离过期还有多少秒

type Config

type Config struct {
	// Disabled 禁用 上层 初始化服务时候 可以判断该属性 如果为 配置 true 则不去初始化服务
	Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"`

	Address            string   `json:"address" yaml:"address"`
	Auth               string   `json:"auth" yaml:"auth"`
	Username           string   `json:"username" yaml:"username"`
	Database           int      `json:"database" yaml:"database"`
	CertPath           string   `json:"certPath" yaml:"certPath"`
	Servers            []string `json:"servers" yaml:"servers"`
	ThrowNotFoundErr   bool     `json:"throwNotFoundErr" yaml:"throwNotFoundErr"`     // 是否 抛出 值 不存在异常
	InsecureSkipVerify bool     `json:"insecureSkipVerify" yaml:"insecureSkipVerify"` // TLS 跳过验证
	// contains filtered or unexported fields
}

func (*Config) GetConnProxy

func (this_ *Config) GetConnProxy() ConnProxy

func (*Config) SetConnProxy

func (this_ *Config) SetConnProxy(connProxy ConnProxy)

type ConnProxy

type ConnProxy interface {
	Dial(n string, addr string) (net.Conn, error)
}

type CountArg

type CountArg struct {
	Count int64
}

func NewCountArg

func NewCountArg(count int64) *CountArg

func (*CountArg) IsArg

func (this_ *CountArg) IsArg()

type IService

type IService interface {
	// Close 关闭 redis 客户端
	Close()
	// GetClient 获取 redis 指令客户端
	GetClient(args ...Arg) (client redis.Cmdable, err error)
	// Info 获取 redis 信息
	Info(args ...Arg) (res string, err error)
	// Keys 模糊 搜索 key,如 "xx*" 搜索
	Keys(pattern string, args ...Arg) (keysResult *KeysResult, err error)
	// Scan 模糊 搜索 key,如 "xx*" 搜索
	Scan(pattern string, args ...Arg) (keysResult *KeysResult, err error)
	// Expire 设置 key 过期时间 让给定键在指定的秒数之后过期
	Expire(key string, expire int64, args ...Arg) (res bool, err error)
	// Ttl 查看给定键距离过期还有多少秒
	Ttl(key string, args ...Arg) (res int64, err error)
	// Persist 移除键的过期时间
	Persist(key string, args ...Arg) (res bool, err error)
	// Exists 判断 key 是否存在
	Exists(key string, args ...Arg) (res int64, err error)
	ValueType(key string, args ...Arg) (valueType string, err error)
	// GetValueInfo 获取 key 的值信息  string、set、list、hash等值 多个值的情况下 使用 StartArg 和 SizeArg 查询一定数量的值
	GetValueInfo(key string, args ...Arg) (valueInfo *ValueInfo, err error)

	// Get 获取 string 类型的值
	Get(key string, args ...Arg) (value string, err error)
	// Set 设置 string 类型的值
	Set(key string, value string, args ...Arg) (err error)

	Incr(key string, value int64, args ...Arg) (res int64, err error)

	// SetAdd 在 set 中 添加 string 类型的值
	SetAdd(key string, value string, args ...Arg) (err error)
	// SetRem 在 set 中 移除 string 类型的值
	SetRem(key string, value string, args ...Arg) (err error)
	// SetCard 在 set 中 移除 string 类型的值
	SetCard(key string, args ...Arg) (res int64, err error)

	// ListPush 在 list 中 往 头部 追加 string 类型的值
	ListPush(key string, value string, args ...Arg) (err error)
	// ListRPush 在 list 中 往 尾部 追加 string 类型的值
	ListRPush(key string, value string, args ...Arg) (err error)
	// ListSet 在 list 中 往 某个 索引位 设置 string 类型的值
	ListSet(key string, index int64, value string, args ...Arg) (err error)
	// ListRem 在 list 中 根据参数 COUNT 的值,移除列表中与参数 VALUE 相等的元素 count > 0 : 从表头开始向表尾搜索,移除与 VALUE 相等的元素,数量为 COUNT count < 0 : 从表尾开始向表头搜索,移除与 VALUE 相等的元素,数量为 COUNT 的绝对值 count = 0 : 移除表中所有与 VALUE 相等的值
	ListRem(key string, count int64, value string, args ...Arg) (err error)

	// HashSet 在 hash 中 设置 字段 的值
	HashSet(key string, field string, value string, args ...Arg) (err error)
	// HashGet 在 hash 中 获取 字段 的值
	HashGet(key string, field string, args ...Arg) (value string, err error)
	// HashGetAll 在 hash 中 获取 所有 字段 的值
	HashGetAll(key string, args ...Arg) (value map[string]string, err error)
	// HashDel 在 hash 中 删除 字段 的值
	HashDel(key string, field string, args ...Arg) (err error)

	// Del 删除 某个 key
	Del(key string, args ...Arg) (count int, err error)
	// DelPattern 模糊删除 匹配 key
	DelPattern(pattern string, args ...Arg) (count int, err error)
	// BitSet 在 bitmap 中 设置 某个 位置的值
	BitSet(key string, offset int64, value int, args ...Arg) (err error)
	// BitCount 在 bitmap 中 统计 所有 值
	BitCount(key string, args ...Arg) (count int64, err error)
	ScriptRun(src string, KEYS []string, ARGV interface{}, args ...Arg) (value interface{}, err error)
	SetThrowNotFoundErr(ThrowNotFoundErr bool)
	IsNotFound(err error) (res bool)
}

func New

func New(config *Config) (service IService, err error)

New 创建Redis服务

func NewClusterService

func NewClusterService(config *Config) (IService, error)

NewClusterService 创建集群客户端

func NewRedisService

func NewRedisService(config *Config) (IService, error)

NewRedisService 创建客户端

type KeysResult

type KeysResult struct {
	Count    int64    `json:"count"`
	KeyList  []string `json:"keyList"`
	Database int      `json:"database"`
}

func ClusterKeys

func ClusterKeys(ctx context.Context, client *redis.ClusterClient, database int, pattern string, size int64) (keysResult *KeysResult, err error)

func ClusterScan

func ClusterScan(ctx context.Context, client *redis.ClusterClient, database int, match string, size int64, count int64) (keysResult *KeysResult, err error)

func Keys

func Keys(ctx context.Context, client redis.Cmdable, database int, pattern string, size int64) (keysResult *KeysResult, err error)

func Scan

func Scan(ctx context.Context, client redis.Cmdable, database int, match string, size int64, count int64) (keysResult *KeysResult, err error)

type Locker

type Locker struct {
	// contains filtered or unexported fields
}

func NewLocker

func NewLocker(service IService) *Locker

func (*Locker) Lock

func (this_ *Locker) Lock(ctx context.Context, lockKey string, timeout time.Duration) (string, error)

func (*Locker) Unlock

func (this_ *Locker) Unlock(ctx context.Context, lockKey string, token string) error

type Param

type Param struct {
	Ctx      context.Context
	Database int
}

func (*Param) IsArg

func (this_ *Param) IsArg()

type SizeArg

type SizeArg struct {
	Size int64
}

func NewSizeArg

func NewSizeArg(size int64) *SizeArg

func (*SizeArg) IsArg

func (this_ *SizeArg) IsArg()

type StartArg

type StartArg struct {
	Start int
}

func NewStartArg

func NewStartArg(start int) *StartArg

func (*StartArg) IsArg

func (this_ *StartArg) IsArg()

type V8Service

type V8Service struct {
	*Config

	*CmdService
	// contains filtered or unexported fields
}

func (*V8Service) Close

func (this_ *V8Service) Close()

func (*V8Service) DelPattern

func (this_ *V8Service) DelPattern(pattern string, args ...Arg) (count int, err error)

func (*V8Service) GetClient

func (this_ *V8Service) GetClient(args ...Arg) (client redis.Cmdable, err error)

func (*V8Service) GetValueInfo

func (this_ *V8Service) GetValueInfo(key string, args ...Arg) (valueInfo *ValueInfo, err error)

func (*V8Service) Keys

func (this_ *V8Service) Keys(pattern string, args ...Arg) (keysResult *KeysResult, err error)

func (*V8Service) Scan

func (this_ *V8Service) Scan(pattern string, args ...Arg) (keysResult *KeysResult, err error)

func (*V8Service) ValueType

func (this_ *V8Service) ValueType(key string, args ...Arg) (valueType string, err error)

type ValueInfo

type ValueInfo struct {
	Database    int         `json:"database"`
	Key         string      `json:"key"`
	ValueType   string      `json:"valueType"`
	Value       interface{} `json:"value"`
	ValueCount  int64       `json:"valueCount"`
	ValueStart  int64       `json:"valueStart"`
	ValueEnd    int64       `json:"valueEnd"`
	Cursor      uint64      `json:"cursor"`
	MemoryUsage int64       `json:"memoryUsage"`
	TTL         int64       `json:"ttl"`
}

func GetValueInfo

func GetValueInfo(ctx context.Context, client redis.Cmdable, database int, key string, valueStart, valueSize int64) (valueInfo *ValueInfo, err error)

Jump to

Keyboard shortcuts

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