kredis

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnSubscribe   = errors.New("func UnSubscribe be called")
	ErrChannelClosed = errors.New("channel be closed")
)

Functions

func MatchFilter

func MatchFilter(patterns []string, key string) bool

Types

type Empty

type Empty struct{}

type KRedis

type KRedis struct {
	Client *redisHd.Client
	// contains filtered or unexported fields
}

func NewKRedis

func NewKRedis(ctx *kcontext.ContextNode, host string, port int, user string, password string, dbNum int) *KRedis

func (*KRedis) Del

func (mr *KRedis) Del(keys ...string) (int64, error)

删除一批key

func (*KRedis) Do

func (mr *KRedis) Do(args ...interface{}) (interface{}, error)

执行指令

func (*KRedis) Dump

func (mr *KRedis) Dump(key string) (string, error)

func (*KRedis) Exist

func (mr *KRedis) Exist(key string) (bool, error)

判断某个key是否存在

func (*KRedis) Expire added in v0.4.2

func (that *KRedis) Expire(key string, expiration time.Duration) bool

func (*KRedis) ExpireAt added in v0.4.2

func (that *KRedis) ExpireAt(key string, tm time.Time) bool

func (*KRedis) Get

func (mr *KRedis) Get(key string) (interface{}, error)

获取一个key的值

func (*KRedis) HDel

func (that *KRedis) HDel(key string, fields ...string) error

删除一个key的hash字段的值列表

func (*KRedis) HExists

func (that *KRedis) HExists(key string, field string) (bool, error)

判断一个key的hash字段是否存在

func (*KRedis) HGet

func (that *KRedis) HGet(key string, field string) (interface{}, error)

获取一个key的hash字段的值

func (*KRedis) HGetAll

func (that *KRedis) HGetAll(key string) (map[string]string, error)

获取一个key的hash字段的值列表

func (*KRedis) HKeys

func (that *KRedis) HKeys(ctx context.Context, key string) ([]string, error)

获取一个key的hash字段的所有Key

func (*KRedis) HLen

func (that *KRedis) HLen(key string) (int64, error)

获取一个key的hash字段的数量

func (*KRedis) HMGet

func (that *KRedis) HMGet(key string, fields ...string) ([]interface{}, error)

获取一个key的hash字段的值列表

func (*KRedis) HMSet

func (that *KRedis) HMSet(key string, fields map[string]interface{}) error

设置一个key的hash字段的值列表, 如果不存在则创建

func (*KRedis) HSet

func (that *KRedis) HSet(key string, field string, value interface{}) error

设置一个key的hash字段的值

func (*KRedis) HSetAll

func (that *KRedis) HSetAll(key string, fields map[string]interface{}) error

设置一个key的hash字段的值列表

func (*KRedis) HSetNX

func (that *KRedis) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)

设置一个key的hash字段的值列表, 如果不存在则创建

func (*KRedis) HVals

func (that *KRedis) HVals(ctx context.Context, key string) ([]string, error)

获取一个key的hash字段的所有值

func (*KRedis) JsonDel added in v0.4.2

func (that *KRedis) JsonDel(key string, path string) (int64, error)

JsonDel 封装了 Redis JSON.DEL 命令。 key: Redis 中的键名。 path: 可选的 JSON Path。如果为空字符串,则删除整个 JSON 文档。 返回值:被删除的 JSON 值数量。如果键或路径不存在,通常返回 0。

func (*KRedis) JsonGet added in v0.4.2

func (that *KRedis) JsonGet(key string, paths ...string) (string, error)

JsonGet 封装了 Redis JSON.GET 命令,并直接返回原始的 JSON 字符串。 调用方将负责对返回的字符串进行反序列化。 key: Redis 中的键名。 paths: 可选的 JSON Path 参数。如果没有提供,则获取整个 JSON 文档。 返回值:JSON 字符串。如果键或路径不存在,或结果为空,则返回空字符串和 nil 错误。

func (*KRedis) JsonMerge added in v0.4.2

func (that *KRedis) JsonMerge(key string, path string, value string) error

JsonMerge 封装了 Redis JSON.MERGE 命令。 该命令会将 Go 值序列化为 JSON 并与现有值合并。如果路径不存在,则创建新字段。 key: Redis 中的键名。 path: JSON Path,指定要合并的位置。 value: 要存储的 Go 值,将被序列化为 JSON 并与现有值合并。 返回值:如果操作成功则返回 nil,否则返回错误。

func (*KRedis) JsonObjKeys added in v0.4.2

func (that *KRedis) JsonObjKeys(key string, path string) ([]string, error)

JsonObjKeys 封装了 Redis JSON.OBJKEYS 命令。 key: Redis 中的键名。 path: 可选的 JSON Path。如果为空字符串,则返回根对象的键。 返回值:一个包含对象键的字符串切片。如果键、路径不存在或路径对应的不是对象,则返回 nil 切片和 nil 错误。

func (*KRedis) JsonObjLen added in v0.4.2

func (that *KRedis) JsonObjLen(key string, path string) ([]int64, error)

OBJLEN 获取JSON 对象中键的数量,如果匹配的 JSON 值不是对象,则为 -1 key: Redis 中的键名。 path: 可选的 JSON Path。如果为空字符串,则返回根对象的键。 返回值:一个包含对象键的字符串切片。如果键、路径不存在或路径对应的不是对象,则返回 nil 切片和 nil 错误。

func (*KRedis) JsonSet added in v0.4.2

func (that *KRedis) JsonSet(key string, path string, value string) error

JsonSet 封装了 Redis JSON.SET 命令。 它会将 Go 值自动序列化为 JSON 字符串并存储。 key: Redis 中的键名。 path: JSON Path。 value: 要存储的 Go 值,将被序列化为 JSON。 返回值:如果操作成功则返回 nil,否则返回错误。

func (*KRedis) JsonType added in v0.4.2

func (that *KRedis) JsonType(key string, path string) ([]string, error)

JsonType 封装了 Redis JSON.TYPE 命令。 key: Redis 中的键名。 path: 可选的 JSON Path。如果为空字符串,则返回根路径的类型; 不支持同时指定多个路径。 返回值:一个包含 JSON 值类型的字符串切片。如果键或路径不存在,则返回 nil 切片和 nil 错误。

func (*KRedis) LIndex

func (that *KRedis) LIndex(key string, index int64) (string, error)

根据索引坐标,查询列表中的数据

func (*KRedis) LInsert

func (that *KRedis) LInsert(key string, position string, pivot interface{}, value interface{}) (int64, error)

在指定位置插入数据,在头部插入用"before",尾部插入用"after"

func (*KRedis) LLen

func (that *KRedis) LLen(key string) (int64, error)

返回列表的大小

func (*KRedis) LPop

func (that *KRedis) LPop(key string) (string, error)

从列表左边弹出数据

func (*KRedis) LPush

func (that *KRedis) LPush(key string, values ...interface{}) (int64, error)

从列表左边插入数据

func (*KRedis) LPushX

func (that *KRedis) LPushX(key string, values ...interface{}) (int64, error)

从列表左边插入数据, 如果不存在则不插入数据

func (*KRedis) LRange

func (that *KRedis) LRange(key string, start int64, stop int64) ([]string, error)

返回列表的一个范围内的数据,也可以返回全部数据

func (*KRedis) LRem

func (that *KRedis) LRem(key string, count int64, value interface{}) (int64, error)

删除列表中的数据

func (*KRedis) LSet

func (that *KRedis) LSet(key string, index int64, value interface{}) error

func (*KRedis) LTrim

func (that *KRedis) LTrim(key string, start int64, stop int64) error

func (*KRedis) PSubscribe

func (mr *KRedis) PSubscribe(timeout int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, topic支持通配符, timeout 设置轮询超时时间, 单位ms; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) PSubscribeLow added in v0.4.11

func (mr *KRedis) PSubscribeLow(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, 底层API, 最好使用Subscribe替代

func (*KRedis) PSubscribeWithChanSize

func (mr *KRedis) PSubscribeWithChanSize(timeout int, chanSize int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, topic支持通配符, timeout 设置轮询超时时间, 单位ms; chanSize 最大允许队列大小, 如果< 1, 则为1; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) PTTL

func (mr *KRedis) PTTL(key string) (time.Duration, error)

返回一个Key的过期时间, 单位为毫秒

func (*KRedis) Ping

func (mr *KRedis) Ping() bool

探测服务是否正常

func (*KRedis) Pipeline

func (mr *KRedis) Pipeline() redisHd.Pipeliner

func (*KRedis) Publish

func (mr *KRedis) Publish(topic string, payload interface{}) error

向指定topic发布消息

func (*KRedis) RPop

func (that *KRedis) RPop(key string) (string, error)

从列表右边弹出数据

func (*KRedis) RPush

func (that *KRedis) RPush(key string, values ...interface{}) (int64, error)

从列表右边插入数据

func (*KRedis) RPushX

func (that *KRedis) RPushX(key string, values ...interface{}) (int64, error)

从列表右边插入数据, 如果不存在则不插入数据

func (*KRedis) Restore

func (mr *KRedis) Restore(key string, ttl time.Duration, value string) (string, error)

func (*KRedis) RestoreReplace

func (mr *KRedis) RestoreReplace(key string, ttl time.Duration, value string) (string, error)

func (*KRedis) SAdd

func (that *KRedis) SAdd(key string, members ...interface{}) (int64, error)

func (*KRedis) SCard

func (that *KRedis) SCard(key string) (int64, error)

func (*KRedis) SDiff

func (that *KRedis) SDiff(keys ...string) ([]string, error)

func (*KRedis) SDiffStore

func (that *KRedis) SDiffStore(destKey string, keys ...string) (int64, error)

func (*KRedis) SInter

func (that *KRedis) SInter(keys ...string) ([]string, error)

func (*KRedis) SInterStore

func (that *KRedis) SInterStore(destKey string, keys ...string) (int64, error)

func (*KRedis) SIsMember

func (that *KRedis) SIsMember(key string, member interface{}) (bool, error)

func (*KRedis) SMembers

func (that *KRedis) SMembers(key string) ([]string, error)

func (*KRedis) SMove

func (that *KRedis) SMove(source, destination string, member interface{}) (bool, error)

func (*KRedis) SPop

func (that *KRedis) SPop(key string) (string, error)

func (*KRedis) SPopN

func (that *KRedis) SPopN(key string, count int64) ([]string, error)

func (*KRedis) SRandMember

func (that *KRedis) SRandMember(key string) (string, error)

func (*KRedis) SRem

func (that *KRedis) SRem(key string, members ...interface{}) (int64, error)

func (*KRedis) SUnion

func (that *KRedis) SUnion(keys ...string) ([]string, error)

func (*KRedis) SUnionStore

func (that *KRedis) SUnionStore(destKey string, keys ...string) (int64, error)

func (*KRedis) Scan

func (mr *KRedis) Scan(limit int, aboutTypes []string, ignoreKeys []string, includeKeys []string, needDel bool, logf klogger.AppLogFunc) ([]*RedisRecord, error)

func (*KRedis) ScanMatch

func (mr *KRedis) ScanMatch(limit int, aboutTypes []string, ignoreKeys []string, includeKeys []string, needDel bool, logf klogger.AppLogFunc) ([]*RedisRecord, error)

func (*KRedis) Set

func (mr *KRedis) Set(key string, value interface{}, duration time.Duration) (bool, error)

设置某个key的值, 并指定ttl

func (*KRedis) Stop

func (mr *KRedis) Stop()

func (*KRedis) Subscribe

func (mr *KRedis) Subscribe(timeout int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, timeout 设置轮询超时时间, 单位ms; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) SubscribeLow

func (mr *KRedis) SubscribeLow(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, 底层API, 最好使用Subscribe替代

func (*KRedis) SubscribeWithoutTimeout

func (mr *KRedis) SubscribeWithoutTimeout(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息

func (*KRedis) SyncPSubscribe added in v0.4.12

func (mr *KRedis) SyncPSubscribe(timeout int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, topic支持通配符, timeout 设置轮询超时时间, 单位ms; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) SyncPSubscribeLow added in v0.4.12

func (mr *KRedis) SyncPSubscribeLow(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, 底层API, 最好使用Subscribe替代

func (*KRedis) SyncPSubscribeWithChanSize added in v0.4.12

func (mr *KRedis) SyncPSubscribeWithChanSize(timeout int, chanSize int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, topic支持通配符, timeout 设置轮询超时时间, 单位ms; chanSize 最大允许队列大小, 如果< 1, 则为1; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) SyncSubscribe added in v0.4.12

func (mr *KRedis) SyncSubscribe(timeout int, callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, timeout 设置轮询超时时间, 单位ms; callback为接收消息的回调函数; topics为需要订阅的topic

func (*KRedis) SyncSubscribeLow added in v0.4.12

func (mr *KRedis) SyncSubscribeLow(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息, 底层API, 最好使用Subscribe替代

func (*KRedis) SyncSubscribeWithoutTimeout added in v0.4.12

func (mr *KRedis) SyncSubscribeWithoutTimeout(callback func(err error, topic string, payload interface{}), topics ...string)

从指定topic订阅消息

func (*KRedis) TTL

func (mr *KRedis) TTL(key string) (time.Duration, error)

返回一个Key的过期时间, 单位为秒

func (*KRedis) Type

func (mr *KRedis) Type(key string) (string, error)

获取一个key的数据类型, 数据类型全小写

type RedisMessage

type RedisMessage struct {
	Topic   string
	Message string
}

type RedisMessagePackConstraints

type RedisMessagePackConstraints interface {
	RedisRecord | RedisMessage
}

type RedisRecord

type RedisRecord struct {
	Key      string
	DataType string
	PTtl     time.Duration
	Data     string
}

Jump to

Keyboard shortcuts

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