Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrDeadlock = errors.New("trying to acquire a lock twice by the same process")
)
Functions ¶
Types ¶
type DLockByRedis ¶
type DLockByRedis struct {
// contains filtered or unexported fields
}
DLockByRedis 通过redis实现的分布式锁
func NewDLockByRedis ¶
func NewDLockByRedis(p *RedisConnPool) *DLockByRedis
NewDLockByRedis 获取DLockByRedis实例.
type DLockByZookeeper ¶
type DLockByZookeeper struct {
// contains filtered or unexported fields
}
DLockByZookeeper 通过zookeeper实现的分布式锁
func NewDLockByZookeeper ¶
func NewDLockByZookeeper(conn *zk.Conn) *DLockByZookeeper
NewDLockByZookeeper 获取DLockByZookeeper实例.
func (*DLockByZookeeper) TryLock ¶
func (dlz *DLockByZookeeper) TryLock(timeoutInSecs int) bool
TryLock 尝试获取分布式锁, 超时后就放弃 (不可重入锁).
==> acquire lock n = create("/distlock/fast-lock/request-", "", ephemeral|sequence) RETRY:
children = getChildren("/distlock/fast-lock", watch=False)
if n is lowest znode in children:
return
else:
exist("/distlock/fast-lock/request-" % (n - 1), watch=True)
watch_event:
goto RETRY
func (*DLockByZookeeper) Unlock ¶
func (dlz *DLockByZookeeper) Unlock()
Unlock 释放分布式锁.
==> release lock (voluntarily or session timeout) delete("/distlock/fast-lock/request-" % n)
type RedisConnPool ¶
type RedisConnPool struct {
// contains filtered or unexported fields
}
func EstablishRedisConn ¶
func EstablishRedisConn(cfg *RedisServiceConfig) *RedisConnPool
EstablishRedisConn 建立连接redis服务的TCP连接池.
func (*RedisConnPool) ExecCommand ¶
func (p *RedisConnPool) ExecCommand(cmd string, args ...interface{}) (interface{}, error)
ExecCommand 执行redis命令, 完成后自动归还连接.
func (*RedisConnPool) ExecLuaScript ¶
func (p *RedisConnPool) ExecLuaScript(src string, keyCount int, keysAndArgs ...interface{}) (interface{}, error)
ExecLuaScript 执行lua脚本, 完成后自动归还连接.
type RedisServiceConfig ¶
type RedisServiceConfig struct {
SentinelEndpoints []string `json:"sentinel_endpoints"`
SentinelMasterName string `json:"sentinel_master_name"`
SentinelPassword string `json:"sentinel_password"`
RedisDatabase int `json:"redis_database"`
RedisMasterPassword string `json:"redis_master_password"`
RedisPoolMaxIdleConns int `json:"redis_pool_max_idle_conns"` // 连接池最大空闲连接数
RedisPoolMaxActiveConns int `json:"redis_pool_max_active_conns"` // 连接池最大激活连接数
RedisConnectTimeoutMsec int `json:"redis_connect_timeout_msec"` // 连接超时
RedisReadTimeoutMsec int `json:"redis_read_timeout_msec"` // 读取超时
RedisWriteTimeoutMsec int `json:"redis_write_timeout_msec"` // 写入超时
}