Documentation
¶
Index ¶
- func CloseZKConn(conn *zk.Conn)
- func EstablishZKConn(endpoints []string, timeout int64) (*zk.Conn, <-chan zk.Event)
- func SkipAutoTest(t *testing.T)
- type DlockByRedis
- type DlockByZookeeper
- type RedisConnInterface
- type RedisConnPool
- type RedisConnPoolConfig
- type RedisHAConnPool
- type RedisHAConnPoolConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstablishZKConn ¶
EstablishZKConn 建立一条连接zookeeper集群的TCP连接.
func SkipAutoTest ¶
Types ¶
type DlockByRedis ¶
type DlockByRedis struct {
// contains filtered or unexported fields
}
DlockByRedis 通过redis实现的分布式锁服务
func NewDlockByRedis ¶
func NewDlockByRedis(rdb RedisConnInterface) *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(pid string, timeout int64) (token string, acquired bool)
TryLock 尝试获取分布式锁, 超时后就放弃 (不可重入锁).
==> acquire lock n = create("/dlock/fast-lock/request-", "", ephemeral|sequence) RETRY:
children = getChildren("/dlock/fast-lock", watch=False) if n is lowest znode in children: return else: exist("/dlock/fast-lock/request-" % (n - 1), watch=True)
watch_event:
goto RETRY
func (*DlockByZookeeper) Unlock ¶
func (dlz *DlockByZookeeper) Unlock(pid, token string)
Unlock 释放分布式锁.
==> release lock (voluntarily or session timeout) delete("/dlock/fast-lock/request-" % n)
type RedisConnInterface ¶
type RedisConnPool ¶
type RedisConnPool struct {
// contains filtered or unexported fields
}
func EstablishRedisConn ¶
func EstablishRedisConn(cfg *RedisConnPoolConfig) *RedisConnPool
EstablishRedisConn 建立连接redis服务的TCP连接池.
func (*RedisConnPool) ExecCmd ¶
func (p *RedisConnPool) ExecCmd(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 RedisConnPoolConfig ¶
type RedisConnPoolConfig struct { RedisEndpoint string `json:"redis_endpoint"` RedisDatabase int `json:"redis_database"` RedisPassword string `json:"redis_password"` RedisConnectTimeout int `json:"redis_connect_timeout_msec"` // 连接超时 RedisReadTimeout int `json:"redis_read_timeout_msec"` // 读取超时 RedisWriteTimeout int `json:"redis_write_timeout_msec"` // 写入超时 RedisPoolMaxIdleConns int `json:"redis_pool_max_idle_conns"` // 连接池最大空闲连接数 RedisPoolMaxActiveConns int `json:"redis_pool_max_active_conns"` // 连接池最大激活连接数 RedisOpenTLS bool `json:"redis_open_tls"` }
type RedisHAConnPool ¶
type RedisHAConnPool struct {
// contains filtered or unexported fields
}
func EstablishRedisHAConnPool ¶
func EstablishRedisHAConnPool(cfg *RedisHAConnPoolConfig) *RedisHAConnPool
EstablishRedisHAConnPool 建立连接redis服务的TCP连接池.
func (*RedisHAConnPool) ExecCmd ¶
func (p *RedisHAConnPool) ExecCmd(cmd string, args ...interface{}) (interface{}, error)
ExecCommand 执行redis命令, 完成后自动归还连接.
func (*RedisHAConnPool) ExecLuaScript ¶
func (p *RedisHAConnPool) ExecLuaScript(src string, keyCount int, keysAndArgs ...interface{}) (interface{}, error)
ExecLuaScript 执行lua脚本, 完成后自动归还连接.
type RedisHAConnPoolConfig ¶
type RedisHAConnPoolConfig struct { SentinelEndpoints []string `json:"sentinel_endpoints"` SentinelMasterName string `json:"sentinel_master_name"` SentinelPassword string `json:"sentinel_password"` SentinelOpenTLS bool `json:"sentinel_open_tls"` RedisDatabase int `json:"redis_database"` RedisMasterPassword string `json:"redis_master_password"` RedisConnectTimeout int `json:"redis_connect_timeout_msec"` // 连接超时 RedisReadTimeout int `json:"redis_read_timeout_msec"` // 读取超时 RedisWriteTimeout int `json:"redis_write_timeout_msec"` // 写入超时 RedisPoolMaxIdleConns int `json:"redis_pool_max_idle_conns"` // 连接池最大空闲连接数 RedisPoolMaxActiveConns int `json:"redis_pool_max_active_conns"` // 连接池最大激活连接数 }
Click to show internal directories.
Click to hide internal directories.