Documentation
¶
Index ¶
- Constants
- type ConnectConfig
- type CountLock
- func (cl *CountLock) Current(key interface{}) (int, error)
- func (cl *CountLock) DecrBy(key interface{}, count int64) (int, error)
- func (cl *CountLock) Existed(key interface{}) (bool, error)
- func (cl *CountLock) IncrBy(key interface{}, count int64) (int, error)
- func (cl *CountLock) Start(key interface{}, startWith int, expired time.Duration) error
- func (cl *CountLock) StopCounter(key interface{}) error
- type DistributedLock
- type DistributedQueue
- func (q *DistributedQueue) List(key string, start, stop int64, f func([]string) error) error
- func (q *DistributedQueue) Pop(key string, out interface{}) error
- func (q *DistributedQueue) Push(key string, values ...interface{}) error
- func (q *DistributedQueue) Set(key string, values ...interface{}) error
- func (q *DistributedQueue) Shift(key string, out interface{}) error
- func (q *DistributedQueue) Size(key string) (int64, error)
- func (q *DistributedQueue) Unshift(key string, values ...interface{}) error
- type ICountLock
- type IDistributedLock
- type IDistributedQueue
- type IKmutex
- type ILimiter
- type IOptimisticLock
- type Kmutex
- type Limiter
- type LockContext
- type OptimisticLock
Constants ¶
View Source
const ( StatusLocked = "locked" StatusNotPersist = "error_persist" StatusInvalidCounter = "invalid_counter" StatusCountdownDone = "countdown_done" Empty = "empty" CantParse = "can't parse" )
View Source
const ( Second = "second" Minute = "minute" Hour = "hour" Day = "day" Week = "week" Restricted = "restricted" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectConfig ¶ added in v1.1.1
type CountLock ¶
type CountLock struct {
// contains filtered or unexported fields
}
func CreateCountLock ¶
CreateCountLock deprecated
func StartCountLock ¶ added in v1.1.1
func StartCountLock(cf *ConnectConfig) (*CountLock, error)
StartCountLock
func (*CountLock) Start ¶
Start: khởi động 1 tiến trình bộ đếm. bắt đầu bằng startWith và thời hạn hiệu lực của bộ đếm là expired Start có thể dùng để reset counter về 1 giá trị nào đó.
func (*CountLock) StopCounter ¶ added in v1.1.3
type DistributedLock ¶
type DistributedLock struct {
// contains filtered or unexported fields
}
func CreateDistributedLock ¶
func CreateDistributedLock(addr, pw, prefix string, timelock time.Duration) (*DistributedLock, error)
CreateDistributedLock deprecated
func StartDistributedLock ¶ added in v1.1.1
func StartDistributedLock(cf *ConnectConfig) (*DistributedLock, error)
func (*DistributedLock) Lock ¶
func (d *DistributedLock) Lock(key string) (*LockContext, error)
func (*DistributedLock) Unlock ¶
func (d *DistributedLock) Unlock(lc *LockContext) error
type DistributedQueue ¶
type DistributedQueue struct {
// contains filtered or unexported fields
}
func ConnectDistributedQueue ¶
func (*DistributedQueue) Pop ¶
func (q *DistributedQueue) Pop(key string, out interface{}) error
func (*DistributedQueue) Push ¶
func (q *DistributedQueue) Push(key string, values ...interface{}) error
func (*DistributedQueue) Set ¶
func (q *DistributedQueue) Set(key string, values ...interface{}) error
func (*DistributedQueue) Shift ¶
func (q *DistributedQueue) Shift(key string, out interface{}) error
func (*DistributedQueue) Unshift ¶
func (q *DistributedQueue) Unshift(key string, values ...interface{}) error
type ICountLock ¶
type ICountLock interface {
// Start is config start
Start(key interface{}, startWith int, expired time.Duration) error
// DecrBy decrease count
DecrBy(key interface{}, count int64) (int, error)
// Current get current count
Current(key interface{}) (int, error)
// Existed check key existed
Existed(key interface{}) (bool, error)
// IncrBy increase count
IncrBy(key interface{}, count int64) (int, error)
// IncrBy stop counter
StopCounter(key interface{}) error
}
type IDistributedLock ¶
type IDistributedLock interface {
// Lock is close request in. Lock all request come to the gate
Lock(key string) (*LockContext, error)
// Unlock release the gate
Unlock(lc *LockContext) error
}
type IDistributedQueue ¶
type IDistributedQueue interface {
// Push to the left
Unshift(key string, values ...interface{}) error
// Push to the right
Push(key string, values ...interface{}) error
// release 1 item right
Pop(key string, out interface{}) error
// release 1 item right
Shift(key string, out interface{}) error
// List item in list
List(key string, start, stop int64, f func([]string) error) error
// Size get current size of list
Size(key string) (int64, error)
}
type ILimiter ¶
type ILimiter interface {
// Allow is access comming request and increase counter
Allow(key string, per string, count int) error
// Immediate reset counter
Reset(key string) error
// Allow using with duration = day
// AllowInDay(key string, count int) error
AllowInWeek(key string, count int) error
}
Copyright (c) 2017 Pavel Pravosud https://github.com/rwz/redis-gcra/blob/master/vendor/perform_gcra_ratelimit.lua
type IOptimisticLock ¶
type Kmutex ¶
type Kmutex struct {
// contains filtered or unexported fields
}
Kmutex Can be locked by unique ID
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func CreateLimiter ¶
CreateLimiter deprecated
func StartLimiter ¶ added in v1.1.1
func StartLimiter(cf *ConnectConfig) (*Limiter, error)
func (*Limiter) AllowInWeek ¶ added in v1.1.4
type LockContext ¶
type LockContext struct {
// contains filtered or unexported fields
}
type OptimisticLock ¶
type OptimisticLock struct {
// contains filtered or unexported fields
}
func CreateOptimisticLock ¶
func CreateOptimisticLock(addr, pw, prefix string, timelock time.Duration) (*OptimisticLock, error)
CreateOptimisticLock deprecated
func StartOptimisticLock ¶ added in v1.1.1
func StartOptimisticLock(cf *ConnectConfig) (*OptimisticLock, error)
func (*OptimisticLock) Lock ¶
func (ol *OptimisticLock) Lock(key string, otherDuration ...time.Duration) error
func (*OptimisticLock) Unlock ¶
func (ol *OptimisticLock) Unlock(key string) error
Click to show internal directories.
Click to hide internal directories.