redisx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TTLForever 没有过期时间
	TTLForever = 0
)

Variables

This section is empty.

Functions

func MustParseKeyDuration

func MustParseKeyDuration(s string) time.Duration

MustParseKeyDuration get redis key time expire, if parse got err, expire time return 0

func ParseKeyDuration

func ParseKeyDuration(s string) (time.Duration, error)

ParseKeyDuration get redis key time from string

func RdKey

func RdKey(format string, id ...interface{}) string

RdKey get redis key by format and id slice

func Uint64ToStringRdKeys

func Uint64ToStringRdKeys(format string, ids []uint64) []string

Uint64ToStringRdKeys []uint64 to []string

Types

type Client

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

Client RedisCache

func New

func New(client *redis.Client) *Client

New create redis obj

func (*Client) DelValues

func (c *Client) DelValues(ctx context.Context, keys ...string) error

DelValues using redis client del multi keys

func (*Client) DistrbLock

func (c *Client) DistrbLock(ctx context.Context, lockKey string, ttl time.Duration) error

DistrbLock 通过Redis增加分布式记录锁设计,防止业务操作短时并发

func (*Client) DistrbUnLock

func (c *Client) DistrbUnLock(ctx context.Context, busKey string) error

DistrbUnLock 分布式解锁操作

func (*Client) GetClient

func (c *Client) GetClient() *redis.Client

GetClient get client from Client obj

func (*Client) GetString

func (c *Client) GetString(ctx context.Context, format string, injects ...interface{}) (string, error)

GetString 获取缓存的字符串值,若没有找返回空,若redis失败返回redis操作错误,其他情况正常返回

func (*Client) PipeRead

func (c *Client) PipeRead(ctx context.Context, keys []string) (map[string]string, error)

PipeRead using pipeline read multi keys to map[string]string for each element, map key is redis key, map element value is redis value

func (*Client) PipeWrite

func (c *Client) PipeWrite(ctx context.Context, objs []interface{}, kfn KeyFunc, ttl time.Duration) error

PipeWrite marshal objs to json string one by one, then using pipeline set to redis

type ICurrencyLocker

type ICurrencyLocker interface {
	DistrbLock(ctx context.Context, lockKey string, ttl time.Duration) error
	DistrbUnLock(ctx context.Context, busKey string) error
}

ICurrencyLocker 分布式并发锁接口,支持通过业务操作唯一Key进行短时间锁定

type IRedisHand

type IRedisHand interface {
	// GetClient 获取实例
	GetClient() *redis.Client

	// PipeWrite 管道写
	PipeWrite(ctx context.Context, objs []interface{}, kfn KeyFunc, ttl time.Duration) error

	// PipeRead 管道读取
	PipeRead(ctx context.Context, keys []string) (map[string]string, error)

	// GetString 按格式获取
	GetString(ctx context.Context, keyFormat string, injects ...interface{}) (string, error)

	// DelValues 通过key批量删除值
	DelValues(ctx context.Context, keys ...string) error
}

IRedisHand redis interface

type KeyFunc

type KeyFunc func(obj interface{}) string

KeyFunc get redis key from interface object, g and its field value

eg. kfn := func(obj interface{}) string { return fmt.sprintf("uid:%s", obj.(*User).uid)}

Jump to

Keyboard shortcuts

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