redis

package
v0.0.0-...-6fe9b21 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InternalCodeFailed     = 999 // 未取到锁
	InternalCodeErr        = 998 // 连接异常
	InternalCodeLockNotOwn = 997 // 不是自己的锁
	InternalCodeExLtLease  = 996 // 有效期必须大于续租+minInterval时间
)

Variables

View Source
var Cache = &cache{
	pool: make(map[string]*redis.Client),
}

Functions

func GetRedis

func GetRedis(name string) *redis.Client

func LoadRedis

func LoadRedis(name string, config Config)

LoadRedis 加载指定Redis

func TryLock

func TryLock(ctx context.Context, conn *redis.Client, key string, ex, lease int, leaseId snowflake.ID) (context.CancelFunc, error)

TryLock 尝试获取锁

func UnLock

func UnLock(ctx context.Context, conn *redis.Client, cancelFunc context.CancelFunc, key string, leaseId snowflake.ID) (bool, error)

UnLock 取消分布式锁

Types

type Config

type Config struct {
	Addr        string // 地址
	Pass        string
	DB          int
	MaxIdle     int // 最大闲置连接数
	MaxActive   int // 最大连接数
	IdleTimeout int // 闲置连接有效期
}

type LockError

type LockError struct {
	Code int
	Msg  string
}

func (LockError) Error

func (le LockError) Error() string

func (LockError) GetCode

func (le LockError) GetCode() int

Jump to

Keyboard shortcuts

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