Documentation ¶
Index ¶
- Variables
- func Init(factory LockerFactory)
- type LocalLockerFactory
- func (llf *LocalLockerFactory) Del(key string)
- func (llf *LocalLockerFactory) Mutex(ctx context.Context, options ...Option) (Locker, error)
- func (llf *LocalLockerFactory) MutexL2(ctx context.Context, options ...Option) (Locker, error)
- func (llf *LocalLockerFactory) RWMutex(ctx context.Context, options ...Option) (RWLocker, error)
- type Locker
- type LockerFactory
- type LockerMeta
- type Option
- type RWLocker
- type RedisClient
- type RedisLockerFactory
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotObtained is returned when a lock cannot be obtained. ErrNotObtained = errors.New("redislock: not obtained") // ErrLockNotHeld is returned when trying to release an inactive lock. ErrLockNotHeld = errors.New("redislock: lock not held") // ErrNotSupport is returned when trying to release an inactive lock. ErrNotSupport = errors.New("redislock: redisL2Locker.Unlock() Method 不需调用。释放锁请使用 redisL2Locker.Lock() 返回的 UnlockHandler。") )
Functions ¶
func Init ¶
func Init(factory LockerFactory)
Types ¶
type LocalLockerFactory ¶
type LocalLockerFactory struct {
// contains filtered or unexported fields
}
LocalLockerFactory 本地锁工厂
type LockerFactory ¶
type LockerFactory interface { Mutex(context.Context, ...Option) (Locker, error) MutexL2(ctx context.Context, options ...Option) (Locker, error) RWMutex(context.Context, ...Option) (RWLocker, error) }
LockerFactory 锁创建工厂实现接口
func NewLocalLockerFactory ¶
func NewLocalLockerFactory() LockerFactory
NewLocalLockerFactory 获取本地所工厂,单例模式
type LockerMeta ¶
type LockerMeta struct {
// contains filtered or unexported fields
}
LockerMeta 锁配置元数据
type RedisClient ¶
type RedisClient interface { SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error) }
RedisClient is a minimal client interface
type RedisLockerFactory ¶
type RedisLockerFactory struct {
// contains filtered or unexported fields
}
RedisLockerFactory 分布式工厂锁实现
func NewRedisLockerFactory ¶
func NewRedisLockerFactory(client RedisClient) *RedisLockerFactory
NewRedisLockerFactory 新建 redis 分布式锁工厂
func (*RedisLockerFactory) Mutex ¶
Mutex tries to obtain a new lock using a key with the given TTL. May return ErrNotObtained if not successful.
Click to show internal directories.
Click to hide internal directories.