redis_tool

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decr

func Decr(ctx context.Context, key string) int64

Decr key值每次递减 1 并返回新值

func DecrBy

func DecrBy(ctx context.Context, key string, incr int64) int64

DecrBy key值每次递减指定数值 并返回新值

func Del

func Del(ctx context.Context, key string) bool

Del 删除 key

func Expire

func Expire(ctx context.Context, key string, ex time.Duration) bool

Expire 设置 key的过期时间

func Get

func Get(ctx context.Context, key string) (bool, string)

Get 获取 key的值

func GetSet

func GetSet(ctx context.Context, key string, value interface{}) (bool, string)

GetSet 设置新值获取旧值

func HDel

func HDel(ctx context.Context, key string, fields ...string) bool

HDel 根据 key和字段名,删除 hash字段,支持批量删除

func HExists

func HExists(ctx context.Context, key, field string) bool

HExists 检测 hash字段名是否存在

func HGet

func HGet(ctx context.Context, key, field string) string

HGet 根据 key和 field字段,查询field字段的值

func HGetAll

func HGetAll(ctx context.Context, key string) map[string]string

HGetAll 根据 key查询所有字段和值

func HKeys

func HKeys(ctx context.Context, key string) []string

HKeys 根据 key返回所有字段名

func HLen

func HLen(ctx context.Context, key string) int64

HLen 根据 key,查询hash的字段数量

func HMGet

func HMGet(ctx context.Context, key string, fields ...string) []interface{}

HMGet 根据key和多个字段名,批量查询多个 hash字段值

func HMSet

func HMSet(ctx context.Context, key string, value map[string]interface{}) bool

HMSet 根据 key和多个字段名和字段值,批量设置 hash字段值

func HSet

func HSet(ctx context.Context, key, field, value string) bool

HSet 根据 key和 field字段设置,field字段的值

func HSetNX

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

HSetNX 如果 field字段不存在,则设置 hash字段值

func Incr

func Incr(ctx context.Context, key string) int64

Incr key值每次加一 并返回新值

func IncrBy

func IncrBy(ctx context.Context, key string, incr int64) int64

IncrBy key值每次加指定数值 并返回新值

func IncrByFloat

func IncrByFloat(ctx context.Context, key string, incrFloat float64) float64

IncrByFloat key值每次加指定浮点型数值 并返回新值

func LIndex

func LIndex(ctx context.Context, key string, index int64) (bool, string)

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

func LInsert

func LInsert(ctx context.Context, key string, pivot int64, value interface{}) bool

LInsert 在列表中 pivot 元素的后面插入 value

func LLen

func LLen(ctx context.Context, key string) int64

LLen 返回列表长度

func LPop

func LPop(ctx context.Context, key string) (bool, string)

LPop 从列表左边删除第一个数据,并返回删除的数据

func LPush

func LPush(ctx context.Context, key string, values ...interface{}) int64

LPush 从列表左边插入数据,并返回列表长度

func LRange

func LRange(ctx context.Context, key string, start, stop int64) []string

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

func LRem

func LRem(ctx context.Context, key string, count int64, value interface{}) bool

LRem 从列表左边开始,删除元素data, 如果出现重复元素,仅删除 count次

func Lock

func Lock(ctx context.Context, key, value string) (bool, error)

重入性key、value需要一样,需要手工处理

func LockCtx

func LockCtx(ctx context.Context, key, value string, seconds int) (bool, error)

func NewRedisSentinelAuto

func NewRedisSentinelAuto() *redis.Client

func RPop

func RPop(ctx context.Context, key string) (bool, string)

RPop 从列表右边删除第一个数据,并返回删除的数据

func RPush

func RPush(ctx context.Context, key string, values ...interface{}) int64

RPush 从列表右边插入数据,并返回列表长度

func SAdd

func SAdd(ctx context.Context, key string, values ...interface{}) bool

SAdd 添加元素到集合中

func SCard

func SCard(ctx context.Context, key string) int64

SCard 获取集合元素个数

func SIsMember

func SIsMember(ctx context.Context, key string, value interface{}) bool

SIsMember 判断元素是否在集合中

func SMembers

func SMembers(ctx context.Context, key string) []string

SMembers 获取集合所有元素

func SPopN

func SPopN(ctx context.Context, key string, count int64) []string

SPopN 随机返回集合中的 count个元素,并且删除这些元素

func SRem

func SRem(ctx context.Context, key string, values ...interface{}) bool

SRem 删除 key集合中的 data元素

func Set

func Set(ctx context.Context, key string, value interface{}) bool

Set 设置 key的值

func SetEX

func SetEX(ctx context.Context, key string, value interface{}, ex time.Duration) bool

SetEX 设置 key的值并指定过期时间

func UnLockCtx

func UnLockCtx(ctx context.Context, key, value string) (bool, error)

Types

type Redis

type Redis struct {
	Write redis.Cmdable
	Read  redis.Cmdable
}

func InitRedisConf

func InitRedisConf(c RedisConf) *Redis

type RedisConf

type RedisConf struct {
	Addrs []string `json:",default=127.0.0.1:6379"`
	//Port         int      `json:",default=6379"`
	Pass         string `json:",optional"`
	Username     string `json:",optional"`
	DB           int    `json:",default=0,range=[0:15]"`
	Type         string `json:",default=standalone,options=standalone|sentinel|cluster"`
	MasterName   string `json:",optional"`
	PoolSize     int    `json:",default=0"`
	MinIdleConns int    `json:",default=10"`
	MaxRetries   int    `json:",default=1,range=[0:3]"`
}

type RedisLock

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

A RedisLock is a redis lock.

func NewAutoRedisLock

func NewAutoRedisLock(client redis.Cmdable, key string, value string) *RedisLock

func NewRedisLock

func NewRedisLock(client redis.Cmdable, key string) *RedisLock

NewRedisLock returns a RedisLock.

func (*RedisLock) Lock

func (rl *RedisLock) Lock() (bool, error)

天生具备重入性

func (*RedisLock) LockCtx

func (rl *RedisLock) LockCtx(ctx context.Context) (bool, error)

func (*RedisLock) SetExpire

func (rl *RedisLock) SetExpire(seconds int)

SetExpire sets the expiration.

func (*RedisLock) UnLock

func (rl *RedisLock) UnLock() (bool, error)

UnLock 解锁

func (*RedisLock) UnLockCtx

func (rl *RedisLock) UnLockCtx(ctx context.Context) (bool, error)

Jump to

Keyboard shortcuts

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