Documentation
¶
Index ¶
- Variables
- type RedisSemaphore
- func (sm *RedisSemaphore) Acquire() error
- func (sm *RedisSemaphore) AcquireWithTimeout(timeout time.Duration) error
- func (sm *RedisSemaphore) Available() (int, error)
- func (sm *RedisSemaphore) AvailableKey() string
- func (sm *RedisSemaphore) CurrentTime() (float64, error)
- func (sm *RedisSemaphore) ExistsKey() string
- func (sm *RedisSemaphore) GrabbedKey() string
- func (sm *RedisSemaphore) Release() error
- func (sm *RedisSemaphore) ReleaseLockKey() string
- func (sm *RedisSemaphore) ReleaseStaleLocks(expires time.Duration) error
- func (sm *RedisSemaphore) Reset() error
- type Semaphore
- type TimeSemaphore
Constants ¶
This section is empty.
Variables ¶
var ( ExistsKey = "EXISTS" GrabbedKey = "GRABBED" AvailableKey = "AVAILABLE" ReleaseLockKey = "RELEASE_LOCK" ResourceValue = "1" DefaultNameSpace = "GOSEM::" )
var (
TimeoutError = errors.New("Timeout error")
)
Functions ¶
This section is empty.
Types ¶
type RedisSemaphore ¶
type RedisSemaphore struct { Client *redis.Client Permits int Namespace string UseLocalTime bool StaleClientTimeout time.Duration // contains filtered or unexported fields }
func NewRedisSemaphore ¶
func NewRedisSemaphore(client *redis.Client, permits int) *RedisSemaphore
func (*RedisSemaphore) Acquire ¶
func (sm *RedisSemaphore) Acquire() error
func (*RedisSemaphore) AcquireWithTimeout ¶
func (sm *RedisSemaphore) AcquireWithTimeout(timeout time.Duration) error
func (*RedisSemaphore) Available ¶
func (sm *RedisSemaphore) Available() (int, error)
func (*RedisSemaphore) AvailableKey ¶
func (sm *RedisSemaphore) AvailableKey() string
func (*RedisSemaphore) CurrentTime ¶
func (sm *RedisSemaphore) CurrentTime() (float64, error)
func (*RedisSemaphore) ExistsKey ¶
func (sm *RedisSemaphore) ExistsKey() string
func (*RedisSemaphore) GrabbedKey ¶
func (sm *RedisSemaphore) GrabbedKey() string
func (*RedisSemaphore) Release ¶
func (sm *RedisSemaphore) Release() error
func (*RedisSemaphore) ReleaseLockKey ¶
func (sm *RedisSemaphore) ReleaseLockKey() string
func (*RedisSemaphore) ReleaseStaleLocks ¶
func (sm *RedisSemaphore) ReleaseStaleLocks(expires time.Duration) error
func (*RedisSemaphore) Reset ¶
func (sm *RedisSemaphore) Reset() error
type Semaphore ¶
type Semaphore struct { Permits int // contains filtered or unexported fields }
Semaphore is a simple semaphore that can be used to coordinate the number of accessing shared data from multiple goroutine.
func NewSemaphore ¶
NewSemaphore returns a new Semaphore object
func (*Semaphore) AcquireWithTimeout ¶
AcquireWithTimeout try to get a new resource, but this operation will be timeout after specified time.
type TimeSemaphore ¶
type TimeSemaphore struct { Permits int Logger *log.Logger // contains filtered or unexported fields }
TimeSemaphore is a semaphore that can be used to coordinate the number of accessing shared data from multiple goroutine with specified time.
func NewTimeSemaphore ¶
func NewTimeSemaphore(permits int, per time.Duration) *TimeSemaphore
NewTimeSemaphore returns a new TimeSemaphore object
func (*TimeSemaphore) Acquire ¶
func (sm *TimeSemaphore) Acquire() error
Acquire gets a new resource
func (*TimeSemaphore) AcquireWithTimeout ¶
func (sm *TimeSemaphore) AcquireWithTimeout(timeout time.Duration) error
AcquireWithTimeout try to get a new resource, but this operation will be timeout after specified time.
func (*TimeSemaphore) Available ¶
func (sm *TimeSemaphore) Available() int
Available gets the number of available resource
func (*TimeSemaphore) Destroy ¶
func (sm *TimeSemaphore) Destroy() bool
Destroy stops observing resources of channels. After call this method, this semaphore object wouldn't be controllable.