kredis

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 context.Context, 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) 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) 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) PSubscribeWithChanSize

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

从指定topic订阅消息, topic支持通配符, timeout 设置轮询超时时间, 单位ms; chanSize 最大允许队列大小, 如果< 100, 则为100; 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) 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