Documentation
¶
Index ¶
- Constants
- Variables
- func InitNamedRedis(ctx context.Context, name string, c *conf.Config) (err error)
- func InitOnceRedis(ctx context.Context, c *conf.Config) (err error)
- func IsRedisReady() bool
- type Redis
- func (r *Redis) GetLockScripter(ctx context.Context) *gredis.Script
- func (r *Redis) GetRenewScripter(ctx context.Context) *gredis.Script
- func (r *Redis) GetUnlockScripter(ctx context.Context) *gredis.Script
- func (r *Redis) LoadLockScript(ctx context.Context) (*gredis.Script, error)
- func (r *Redis) LoadRenewScript(ctx context.Context) (*gredis.Script, error)
- func (r *Redis) LoadUnLockScript(ctx context.Context) (*gredis.Script, error)
- func (r *Redis) Lock(ctx context.Context, lockName string, lockTime int64, acquireTime int) (string, error)
- func (r *Redis) LockSingle(ctx context.Context, lockName string, lockTime int64) (identifier string, err error)
- func (r *Redis) LockWithId(ctx context.Context, lockName string, identifier string, lockTime int64, ...) (string, error)
- func (r *Redis) RenewLock(ctx context.Context, lockName, lockId string, renameTime int) (err error)
- func (r *Redis) Unlock(ctx context.Context, lockName, lockId string) (err error)
Constants ¶
View Source
const ( LockScript = "if redis.call('exists', KEYS[1]) == 0 then return redis.call('setex', KEYS[1], unpack(ARGV)) else return '-1' end" UnlockScript = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) or true end" RenewLockScript = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('expire', KEYS[1],ARGV[2]) or true end" LockPrefix = "lock:" )
View Source
const ( ConnTypeCluster = "cluster" ConnTypeAlone = "alone" ConnTypeSentinel = "sentinel" )
Variables ¶
View Source
var ( ErrConnTypeUnknown = exception.New(-1, "unknown connect type") ErrPing = exception.New(-2, "redis conn error") ErrNoReady = exception.New(-3, "redis is not ready,please init it first") )
View Source
var ( ErrExitsLock = exception.New(-4, "lock exits") ErrAcquiredLock = exception.New(-5, "acquire lock error") ErrAcquiredLockTimeout = exception.New(-6, "acquire lock timeout error") )
Functions ¶
func InitNamedRedis ¶
func IsRedisReady ¶
func IsRedisReady() bool
Types ¶
type Redis ¶
type Redis struct { gredis.UniversalClient *conf.Config }
func GetNamedRedis ¶
func (*Redis) GetRenewScripter ¶
func (*Redis) GetUnlockScripter ¶
func (*Redis) LoadLockScript ¶
func (*Redis) LoadRenewScript ¶
func (*Redis) LoadUnLockScript ¶
func (*Redis) Lock ¶
func (r *Redis) Lock(ctx context.Context, lockName string, lockTime int64, acquireTime int) (string, error)
*
- 获取锁 *
- param: string lockName
- param: int lockTime
- param: int acquireTime
- return: string
func (*Redis) LockSingle ¶
func (r *Redis) LockSingle(ctx context.Context, lockName string, lockTime int64) (identifier string, err error)
*
- 简单获取锁 *
- param: string lockName
- param: int lockTime
- return: string
- return: error
func (*Redis) LockWithId ¶
func (r *Redis) LockWithId(ctx context.Context, lockName string, identifier string, lockTime int64, acquireTime int) (string, error)
*
- 获取锁 *
- param: string lockName
- param: int lockTime
- param: int acquireTime
- return: string
Click to show internal directories.
Click to hide internal directories.