Documentation ¶
Index ¶
- Variables
- type Cache
- type Lock
- type LockClient
- type Option
- func ConfigOption(key string) (option *Option, err error)
- func NewOption() *Option
- func SetAddr(l string) *Option
- func SetDB(l int) *Option
- func SetDialTimeout(l string) *Option
- func SetIdleTimeout(l string) *Option
- func SetLogger(l baselogger.Logger) *Option
- func SetMaxRetries(l int) *Option
- func SetMinIdleConns(l int) *Option
- func SetPassword(l string) *Option
- func SetPoolSize(l int) *Option
- func SetReadTimeout(l string) *Option
- func SetWriteTimeout(l string) *Option
- func (c *Option) MergeOption(opts ...*Option) *Option
- func (c *Option) SetAddr(l string) *Option
- func (c *Option) SetDB(l int) *Option
- func (c *Option) SetDialTimeout(l string) *Option
- func (c *Option) SetIdleTimeout(l string) *Option
- func (c *Option) SetLogger(l baselogger.Logger) *Option
- func (c *Option) SetMaxRetries(l int) *Option
- func (c *Option) SetMinIdleConns(l int) *Option
- func (c *Option) SetPassword(l string) *Option
- func (c *Option) SetPoolSize(l int) *Option
- func (c *Option) SetReadTimeout(l string) *Option
- func (c *Option) SetWriteTimeout(l string) *Option
- type RetryStrategy
Constants ¶
This section is empty.
Variables ¶
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") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { *redis.Client Logger baselogger.Logger }
RedisStub is an unit that handles master and slave.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents an obtained, distributed lock.
func (*Lock) Refresh ¶
Refresh extends the lock with a new TTL. May return ErrNotObtained if refresh is unsuccessful.
type LockClient ¶
type LockClient struct {
// contains filtered or unexported fields
}
LockClient wraps a redis client.
func NewLockClient ¶
func NewLockClient(client *Cache) *LockClient
New creates a new LockClient instance with a custom namespace.
type Option ¶
type Option struct { // Addr 节点连接地址 Addr string // Password 密码 Password string // DB,默认为0, 一般应用不推荐使用DB分片 DB int // PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接 PoolSize int // MaxRedirects 网络相关的错误最大重试次数 默认8次 MaxRetries int // MinIdleConns 最小空闲连接数 MinIdleConns int // DialTimeout 拨超时时间 DialTimeout string // ReadTimeout 读超时 默认3s ReadTimeout string // WriteTimeout 读超时 默认3s WriteTimeout string // IdleTimeout 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭 IdleTimeout string Logger baselogger.Logger }
func SetDialTimeout ¶
func SetIdleTimeout ¶
func SetLogger ¶
func SetLogger(l baselogger.Logger) *Option
func SetMaxRetries ¶
func SetMinIdleConns ¶
func SetPassword ¶
func SetPoolSize ¶
func SetReadTimeout ¶
func SetWriteTimeout ¶
func (*Option) MergeOption ¶
func (*Option) SetDialTimeout ¶
func (*Option) SetIdleTimeout ¶
func (*Option) SetMaxRetries ¶
func (*Option) SetMinIdleConns ¶
func (*Option) SetPassword ¶
func (*Option) SetPoolSize ¶
func (*Option) SetReadTimeout ¶
func (*Option) SetWriteTimeout ¶
type RetryStrategy ¶
type RetryStrategy interface { // NextBackoff returns the next backoff duration. NextBackoff() time.Duration }
RetryStrategy allows to customise the lock retry strategy.
func ExponentialBackoff ¶
func ExponentialBackoff(min, max time.Duration) RetryStrategy
ExponentialBackoff strategy is an optimization strategy with a retry time of 2**n milliseconds (n means number of times). You can set a minimum and maximum value, the recommended minimum value is not less than 16ms.
func LimitRetry ¶
func LimitRetry(s RetryStrategy, max int) RetryStrategy
LimitRetry limits the number of retries to max attempts.
func LinearBackoff ¶
func LinearBackoff(backoff time.Duration) RetryStrategy
LinearBackoff allows retries regularly with customized intervals