redislib

package
v0.0.0-...-3e11984 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: BSD-4-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 锁时间长度,单位为秒
	LOCK_TIMEOUT = 5
)

Variables

This section is empty.

Functions

func RedisSetAddr

func RedisSetAddr(addr string) redisoptions

RedisSetAddr 设置 Redis 的地址,带端口

func RedisSetAuth

func RedisSetAuth(auth string) redisoptions

RedisSetAuth 设置 Redis 的认证密码

func RedisSetErrRetry

func RedisSetErrRetry(errRetry int) redisoptions

RedisSetErrRetry 设置出错重试次数,至少为 1

func RedisSetIdleTimeout

func RedisSetIdleTimeout(idleTimeout time.Duration) redisoptions

RedisSetIdleTimeout 设置 Redis 的最大空闲连接等待时间 超过此时间后,空闲连接将被关闭(秒)

func RedisSetIndexDB

func RedisSetIndexDB(indexdb int) redisoptions

RedisSetIndexDB 设置 Redis 默认的数据库索引

func RedisSetMaxActive

func RedisSetMaxActive(maxactive int) redisoptions

RedisSetMaxActive 设置 Redis 的最大激活连接数 表示同时最多有 N 个连接,为 0 时表示没有限制

func RedisSetMaxIdle

func RedisSetMaxIdle(maxidle int) redisoptions

RedisSetMaxIdle 设置 Redis 的最大空闲连接数 表示即使没有 Redis 连接时依然可以保持 N 个空闲的连接,而不被清除,随时处于待命状态

func RedisSeterrFunc

func RedisSeterrFunc(errF errFunc) redisoptions

RedisSeterrFunc 设置错误处理回调函数

Types

type Args

type Args = map[string]interface{}

Args 是 Redis 命令参数的别名类型

type Locker

type Locker struct {
	LockKey   string // 锁的键
	LockValue string // 锁的值
	// contains filtered or unexported fields
}

func NewLocker

func NewLocker(key, val string, getRedisF func() *RedisHandleModel, thgo *threads.SubThreadGo) *Locker

创建一个新的 Locker 实例

func (*Locker) Lock

func (this *Locker) Lock()

阻塞式获取锁,直到成功或发生错误

func (*Locker) LockCtx

func (this *Locker) LockCtx(ctx context.Context) bool

带上下文的锁获取方法,支持取消操作

func (*Locker) String

func (this *Locker) String() string

返回 Locker 的字符串表示

func (*Locker) TryLock

func (this *Locker) TryLock() bool

尝试获取锁,成功返回 true,失败返回 false

func (*Locker) Unlock

func (this *Locker) Unlock() bool

释放锁

type RedisAccess

type RedisAccess struct {
	DBConobj *redis.Client // Redis 连接池
	// contains filtered or unexported fields
}

RedisAccess 是 Redis 管理器

func NewRedisAccess

func NewRedisAccess(opts ...redisoptions) *RedisAccess

NewRedisAccess 生成新的 Redis 管理器

func (*RedisAccess) Close

func (access *RedisAccess) Close()

Close 关闭 Redis 连接池,通常在关闭服务器时调用

func (*RedisAccess) GetConn

func (access *RedisAccess) GetConn() *RedisHandleModel

GetConn 获取一个可用的 Redis 连接 使用完后应调用 defer conn.Close() 将连接放回池中

type RedisHandleModel

type RedisHandleModel struct {
	*redis.Client
	Ctx context.Context
	// contains filtered or unexported fields
}

RedisHandleModel 封装了 Redis 的一些常用命令

func (*RedisHandleModel) HgetallByBytesMap

func (rd *RedisHandleModel) HgetallByBytesMap(key string) (result map[string][]byte, reserr error)

HgetallByBytesMap 获取 Redis 哈希表中的所有字段和值,返回字节切片类型的 map

func (*RedisHandleModel) HgetallByInt64Map

func (rd *RedisHandleModel) HgetallByInt64Map(key string) (result map[string]int64, reserr error)

HgetallByInt64Map 获取 Redis 哈希表中的所有字段和值,返回 int64 类型的 map

func (*RedisHandleModel) HgetallByStringMap

func (rd *RedisHandleModel) HgetallByStringMap(key string) (result map[string]string, reserr error)

HgetallByStringMap 获取 Redis 哈希表中的所有字段和值,返回字符串类型的 map

Jump to

Keyboard shortcuts

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